diff options
author | Ryan Petrello <rpetrell@redhat.com> | 2018-08-10 18:27:45 +0200 |
---|---|---|
committer | Ryan Petrello <rpetrell@redhat.com> | 2018-08-10 18:45:35 +0200 |
commit | 87235082256e83a6531218771c7a502b91445f69 (patch) | |
tree | 88134e46a85be99cd61b377f1e19f2f2ee8224dd | |
parent | Merge remote-tracking branch 'tower/release_3.3.0' into devel (diff) | |
download | awx-87235082256e83a6531218771c7a502b91445f69.tar.xz awx-87235082256e83a6531218771c7a502b91445f69.zip |
fix failing tests related to 2c4f7911a62af804efc807e496a2d8500760c597
-rw-r--r-- | awx/api/serializers.py | 9 | ||||
-rw-r--r-- | awx/main/management/commands/create_oauth2_token.py | 8 |
2 files changed, 9 insertions, 8 deletions
diff --git a/awx/api/serializers.py b/awx/api/serializers.py index f5d853525c..1972913a9d 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -1067,10 +1067,8 @@ class BaseOAuth2TokenSerializer(BaseSerializer): ).format(self.ALLOWED_SCOPES)) return value - def create(self, validated_data, from_command_line=False): - if not from_command_line: - current_user = self.context['request'].user - validated_data['user'] = current_user + def create(self, validated_data): + validated_data['user'] = self.context['request'].user try: return super(BaseOAuth2TokenSerializer, self).create(validated_data) except oauth2.AccessDeniedError as e: @@ -1088,7 +1086,6 @@ class UserAuthorizedTokenSerializer(BaseOAuth2TokenSerializer): def create(self, validated_data): current_user = self.context['request'].user - validated_data['user'] = current_user validated_data['token'] = generate_token() validated_data['expires'] = now() + timedelta( seconds=settings.OAUTH2_PROVIDER['ACCESS_TOKEN_EXPIRE_SECONDS'] @@ -1109,7 +1106,6 @@ class OAuth2TokenSerializer(BaseOAuth2TokenSerializer): def create(self, validated_data): current_user = self.context['request'].user - validated_data['user'] = current_user validated_data['token'] = generate_token() validated_data['expires'] = now() + timedelta( seconds=settings.OAUTH2_PROVIDER['ACCESS_TOKEN_EXPIRE_SECONDS'] @@ -1140,7 +1136,6 @@ class UserPersonalTokenSerializer(BaseOAuth2TokenSerializer): read_only_fields = ('user', 'token', 'expires', 'application') def create(self, validated_data): - validated_data['user'] = self.context['request'].user validated_data['token'] = generate_token() validated_data['expires'] = now() + timedelta( seconds=settings.OAUTH2_PROVIDER['ACCESS_TOKEN_EXPIRE_SECONDS'] diff --git a/awx/main/management/commands/create_oauth2_token.py b/awx/main/management/commands/create_oauth2_token.py index 2d27566c12..bd4a86da2d 100644 --- a/awx/main/management/commands/create_oauth2_token.py +++ b/awx/main/management/commands/create_oauth2_token.py @@ -24,5 +24,11 @@ class Command(BaseCommand): raise CommandError('The user does not exist.') config = {'user': user, 'scope':'write'} serializer_obj = OAuth2TokenSerializer() - token_record = serializer_obj.create(config, True) + + class FakeRequest(object): + def __init__(self): + self.user = user + + serializer_obj.context['request'] = FakeRequest() + token_record = serializer_obj.create(config) self.stdout.write(token_record.token) |