Skip to content

Commit fbb57be

Browse files
committed
Fixing tests.
1 parent ff7cccf commit fbb57be

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

oauth2_provider/oauth2_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def validate_refresh_token(self, refresh_token, client, request, *args, **kwargs
346346
try:
347347
rt = RefreshToken.objects.get(token=refresh_token)
348348
request.user = rt.user
349-
# Temporary store RefreshToken instance to be reused by self.get_original_scopes.
349+
# Temporary store RefreshToken instance to be reused by get_original_scopes.
350350
request.refresh_token = rt
351351
return rt.application == client
352352

oauth2_provider/tests/test_authorization_code.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import base64
44
import json
55
import datetime
6+
import mock
67

78
from django.test import TestCase, RequestFactory
89
from django.core.urlresolvers import reverse
@@ -479,12 +480,6 @@ def test_refresh_repeating_requests_non_rotating_tokens(self):
479480
"""
480481
Try refreshing an access token with the same refresh token more than once when not rotating tokens.
481482
"""
482-
class NonRotatingOAuth2Validator(OAuth2Validator):
483-
def rotate_refresh_token(self, request):
484-
return False
485-
validator_class = oauth2_settings.OAUTH2_VALIDATOR_CLASS
486-
oauth2_settings.OAUTH2_VALIDATOR_CLASS = NonRotatingOAuth2Validator
487-
488483
self.client.login(username="test_user", password="123456")
489484
authorization_code = self.get_auth()
490485

@@ -504,13 +499,12 @@ def rotate_refresh_token(self, request):
504499
'refresh_token': content['refresh_token'],
505500
'scope': content['scope'],
506501
}
507-
508-
response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
509-
self.assertEqual(response.status_code, 200)
510-
response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
511-
self.assertEqual(response.status_code, 200)
512502

513-
oauth2_settings.OAUTH2_VALIDATOR_CLASS = validator_class
503+
with mock.patch('oauthlib.request_validator.RequestValidator.rotate_refresh_token', return_value=False):
504+
response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
505+
self.assertEqual(response.status_code, 200)
506+
response = self.client.post(reverse('oauth2_provider:token'), data=token_request_data, **auth_headers)
507+
self.assertEqual(response.status_code, 200)
514508

515509
def test_basic_auth_bad_authcode(self):
516510
"""

0 commit comments

Comments
 (0)