diff options
author | Jonathan Huot <JonathanHuot@users.noreply.github.com> | 2019-08-30 11:56:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-30 11:56:43 +0200 |
commit | ca57b0bcae835493d9db8f9bf1f1228b71b8e3f8 (patch) | |
tree | 71f3d2ecee2ffd32da6f030558d0eed91d953895 /tests/oauth2 | |
parent | 1f3fc4bfd4fd51711798186591bf3e3ba5a894be (diff) | |
parent | 11bf0eca2857f5330237e574630dd916d53cd573 (diff) | |
download | oauthlib-ca57b0bcae835493d9db8f9bf1f1228b71b8e3f8.tar.gz |
Merge pull request #700 from hugovk/rm-2.7
Drop support for Python 2.7
Diffstat (limited to 'tests/oauth2')
27 files changed, 21 insertions, 90 deletions
diff --git a/tests/oauth2/rfc6749/clients/test_backend_application.py b/tests/oauth2/rfc6749/clients/test_backend_application.py index aa2ba2b..8d80b39 100644 --- a/tests/oauth2/rfc6749/clients/test_backend_application.py +++ b/tests/oauth2/rfc6749/clients/test_backend_application.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import os from mock import patch diff --git a/tests/oauth2/rfc6749/clients/test_base.py b/tests/oauth2/rfc6749/clients/test_base.py index d48a944..c545c25 100644 --- a/tests/oauth2/rfc6749/clients/test_base.py +++ b/tests/oauth2/rfc6749/clients/test_base.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import datetime from oauthlib import common @@ -295,11 +293,11 @@ class ClientTest(TestCase): u, h, b = client.prepare_refresh_token_request(url, token, scope=scope) self.assertEqual(u, url) self.assertEqual(h, {'Content-Type': 'application/x-www-form-urlencoded'}) - self.assertFormBodyEqual(b, 'grant_type=refresh_token&scope=%s&refresh_token=%s' % (scope, token)) + self.assertFormBodyEqual(b, 'grant_type=refresh_token&scope={}&refresh_token={}'.format(scope, token)) # provide scope while init client = Client(self.client_id, scope=scope) u, h, b = client.prepare_refresh_token_request(url, token, scope=scope) self.assertEqual(u, url) self.assertEqual(h, {'Content-Type': 'application/x-www-form-urlencoded'}) - self.assertFormBodyEqual(b, 'grant_type=refresh_token&scope=%s&refresh_token=%s' % (scope, token)) + self.assertFormBodyEqual(b, 'grant_type=refresh_token&scope={}&refresh_token={}'.format(scope, token)) diff --git a/tests/oauth2/rfc6749/clients/test_legacy_application.py b/tests/oauth2/rfc6749/clients/test_legacy_application.py index 21af4a3..34ea108 100644 --- a/tests/oauth2/rfc6749/clients/test_legacy_application.py +++ b/tests/oauth2/rfc6749/clients/test_legacy_application.py @@ -1,20 +1,14 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import os from mock import patch from oauthlib import signals from oauthlib.oauth2 import LegacyApplicationClient +import urllib.parse as urlparse from ....unittest import TestCase -# this is the same import method used in oauthlib/oauth2/rfc6749/parameters.py -try: - import urlparse -except ImportError: - import urllib.parse as urlparse @patch('time.time', new=lambda: 1000) @@ -32,7 +26,7 @@ class LegacyApplicationClientTest(TestCase): password = "user_password" body = "not=empty" - body_up = "not=empty&grant_type=password&username=%s&password=%s" % (username, password) + body_up = "not=empty&grant_type=password&username={}&password={}".format(username, password) body_kwargs = body_up + "&some=providers&require=extra+arguments" token_json = ('{ "access_token":"2YotnFZFEjr1zCsicMWpAA",' @@ -105,8 +99,8 @@ class LegacyApplicationClientTest(TestCase): # scenario 1, default behavior to not include `client_id` r1 = client.prepare_request_body(username=self.username, password=self.password) - self.assertIn(r1, ('grant_type=password&username=%s&password=%s' % (self.username, self.password, ), - 'grant_type=password&password=%s&username=%s' % (self.password, self.username, ), + self.assertIn(r1, ('grant_type=password&username={}&password={}'.format(self.username, self.password), + 'grant_type=password&password={}&username={}'.format(self.password, self.username), )) # scenario 2, include `client_id` in the body diff --git a/tests/oauth2/rfc6749/clients/test_mobile_application.py b/tests/oauth2/rfc6749/clients/test_mobile_application.py index 622b275..e2bdebe 100644 --- a/tests/oauth2/rfc6749/clients/test_mobile_application.py +++ b/tests/oauth2/rfc6749/clients/test_mobile_application.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import os from mock import patch diff --git a/tests/oauth2/rfc6749/clients/test_service_application.py b/tests/oauth2/rfc6749/clients/test_service_application.py index dc337cf..ba9406b 100644 --- a/tests/oauth2/rfc6749/clients/test_service_application.py +++ b/tests/oauth2/rfc6749/clients/test_service_application.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import os from time import time diff --git a/tests/oauth2/rfc6749/clients/test_web_application.py b/tests/oauth2/rfc6749/clients/test_web_application.py index 092f93e..e3382c8 100644 --- a/tests/oauth2/rfc6749/clients/test_web_application.py +++ b/tests/oauth2/rfc6749/clients/test_web_application.py @@ -1,7 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - -import datetime import os import warnings @@ -13,14 +10,10 @@ from oauthlib.oauth2 import (BackendApplicationClient, Client, WebApplicationClient) from oauthlib.oauth2.rfc6749 import errors, utils from oauthlib.oauth2.rfc6749.clients import AUTH_HEADER, BODY, URI_QUERY +import urllib.parse as urlparse from ....unittest import TestCase -# this is the same import method used in oauthlib/oauth2/rfc6749/parameters.py -try: - import urlparse -except ImportError: - import urllib.parse as urlparse @patch('time.time', new=lambda: 1000) @@ -46,7 +39,7 @@ class WebApplicationClientTest(TestCase): code = "zzzzaaaa" body = "not=empty" - body_code = "not=empty&grant_type=authorization_code&code=%s&client_id=%s" % (code, client_id) + body_code = "not=empty&grant_type=authorization_code&code={}&client_id={}".format(code, client_id) body_redirect = body_code + "&redirect_uri=http%3A%2F%2Fmy.page.com%2Fcallback" body_kwargs = body_code + "&some=providers&require=extra+arguments" diff --git a/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py index bf04a42..2289b58 100644 --- a/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py +++ b/tests/oauth2/rfc6749/endpoints/test_base_endpoint.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - from oauthlib.oauth2 import (FatalClientError, OAuth2Error, RequestValidator, Server) from oauthlib.oauth2.rfc6749 import (BaseEndpoint, diff --git a/tests/oauth2/rfc6749/endpoints/test_client_authentication.py b/tests/oauth2/rfc6749/endpoints/test_client_authentication.py index 133da59..48b5485 100644 --- a/tests/oauth2/rfc6749/endpoints/test_client_authentication.py +++ b/tests/oauth2/rfc6749/endpoints/test_client_authentication.py @@ -9,8 +9,6 @@ We make sure authentication is done by requiring a client object to be set on the request object with a client_id parameter. The client_id attribute prevents this check from being circumvented with a client form parameter. """ -from __future__ import absolute_import, unicode_literals - import json import mock diff --git a/tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py b/tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py index e7c66b6..bda71f7 100644 --- a/tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py +++ b/tests/oauth2/rfc6749/endpoints/test_credentials_preservation.py @@ -3,8 +3,6 @@ The Authorization Code Grant will need to preserve state as well as redirect uri and the Implicit Grant will need to preserve state. """ -from __future__ import absolute_import, unicode_literals - import json import mock diff --git a/tests/oauth2/rfc6749/endpoints/test_error_responses.py b/tests/oauth2/rfc6749/endpoints/test_error_responses.py index 2479836..cdf2b63 100644 --- a/tests/oauth2/rfc6749/endpoints/test_error_responses.py +++ b/tests/oauth2/rfc6749/endpoints/test_error_responses.py @@ -1,7 +1,5 @@ """Ensure the correct error responses are returned for all defined error types. """ -from __future__ import absolute_import, unicode_literals - import json import mock diff --git a/tests/oauth2/rfc6749/endpoints/test_extra_credentials.py b/tests/oauth2/rfc6749/endpoints/test_extra_credentials.py index a12fcd2..6895dcd 100644 --- a/tests/oauth2/rfc6749/endpoints/test_extra_credentials.py +++ b/tests/oauth2/rfc6749/endpoints/test_extra_credentials.py @@ -1,7 +1,5 @@ """Ensure extra credentials can be supplied for inclusion in tokens. """ -from __future__ import absolute_import, unicode_literals - import mock from oauthlib.oauth2 import (BackendApplicationServer, LegacyApplicationServer, diff --git a/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py index ae3deae..0942d96 100644 --- a/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py +++ b/tests/oauth2/rfc6749/endpoints/test_introspect_endpoint.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - from json import loads from mock import MagicMock diff --git a/tests/oauth2/rfc6749/endpoints/test_metadata.py b/tests/oauth2/rfc6749/endpoints/test_metadata.py index 4813b46..a01500f 100644 --- a/tests/oauth2/rfc6749/endpoints/test_metadata.py +++ b/tests/oauth2/rfc6749/endpoints/test_metadata.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - from oauthlib.oauth2 import MetadataEndpoint from oauthlib.oauth2 import TokenEndpoint from oauthlib.oauth2 import Server diff --git a/tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py b/tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py index e823286..9e9d836 100644 --- a/tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py +++ b/tests/oauth2/rfc6749/endpoints/test_resource_owner_association.py @@ -1,7 +1,5 @@ """Ensure all tokens are associated with a resource owner. """ -from __future__ import absolute_import, unicode_literals - import json import mock diff --git a/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py index 17be3a5..0e3b2e1 100644 --- a/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py +++ b/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - from json import loads from mock import MagicMock diff --git a/tests/oauth2/rfc6749/endpoints/test_scope_handling.py b/tests/oauth2/rfc6749/endpoints/test_scope_handling.py index 4f27963..65e0e3c 100644 --- a/tests/oauth2/rfc6749/endpoints/test_scope_handling.py +++ b/tests/oauth2/rfc6749/endpoints/test_scope_handling.py @@ -3,8 +3,6 @@ Fairly trivial in all grants except the Authorization Code Grant where scope need to be persisted temporarily in an authorization code. """ -from __future__ import absolute_import, unicode_literals - import json import mock @@ -65,13 +63,13 @@ class TestScopeHandling(TestCase): for scope, correct_scopes in scopes: scopes, _ = self.web.validate_authorization_request( uri % (scope, 'code')) - self.assertItemsEqual(scopes, correct_scopes) + self.assertCountEqual(scopes, correct_scopes) scopes, _ = self.mobile.validate_authorization_request( uri % (scope, 'token')) - self.assertItemsEqual(scopes, correct_scopes) + self.assertCountEqual(scopes, correct_scopes) scopes, _ = self.server.validate_authorization_request( uri % (scope, 'code')) - self.assertItemsEqual(scopes, correct_scopes) + self.assertCountEqual(scopes, correct_scopes) def test_scope_preservation(self): scope = 'pics+http%3A%2f%2fa.b%2fvideos' diff --git a/tests/oauth2/rfc6749/endpoints/test_utils.py b/tests/oauth2/rfc6749/endpoints/test_utils.py index 6b7cff8..5eae195 100644 --- a/tests/oauth2/rfc6749/endpoints/test_utils.py +++ b/tests/oauth2/rfc6749/endpoints/test_utils.py @@ -1,7 +1,4 @@ -try: - import urlparse -except ImportError: - import urllib.parse as urlparse +import urllib.parse as urlparse def get_query_credentials(uri): diff --git a/tests/oauth2/rfc6749/grant_types/test_authorization_code.py b/tests/oauth2/rfc6749/grant_types/test_authorization_code.py index 2c9db3c..4ed9086 100644 --- a/tests/oauth2/rfc6749/grant_types/test_authorization_code.py +++ b/tests/oauth2/rfc6749/grant_types/test_authorization_code.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import json import mock diff --git a/tests/oauth2/rfc6749/grant_types/test_client_credentials.py b/tests/oauth2/rfc6749/grant_types/test_client_credentials.py index edc6bfe..d994278 100644 --- a/tests/oauth2/rfc6749/grant_types/test_client_credentials.py +++ b/tests/oauth2/rfc6749/grant_types/test_client_credentials.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import json import mock diff --git a/tests/oauth2/rfc6749/grant_types/test_implicit.py b/tests/oauth2/rfc6749/grant_types/test_implicit.py index 0c18cab..ffd766a 100644 --- a/tests/oauth2/rfc6749/grant_types/test_implicit.py +++ b/tests/oauth2/rfc6749/grant_types/test_implicit.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import mock from oauthlib.common import Request diff --git a/tests/oauth2/rfc6749/grant_types/test_refresh_token.py b/tests/oauth2/rfc6749/grant_types/test_refresh_token.py index 32a0977..074f359 100644 --- a/tests/oauth2/rfc6749/grant_types/test_refresh_token.py +++ b/tests/oauth2/rfc6749/grant_types/test_refresh_token.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import json import mock diff --git a/tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py b/tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py index 82e0524..4e93015 100644 --- a/tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py +++ b/tests/oauth2/rfc6749/grant_types/test_resource_owner_password.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import json import mock diff --git a/tests/oauth2/rfc6749/test_parameters.py b/tests/oauth2/rfc6749/test_parameters.py index 48b7eac..e9b3621 100644 --- a/tests/oauth2/rfc6749/test_parameters.py +++ b/tests/oauth2/rfc6749/test_parameters.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, unicode_literals - from mock import patch from oauthlib import signals @@ -77,9 +75,9 @@ class ParameterTests(TestCase): error_invalid = 'https://client.example.com/cb?error=invalid_request&state=xyz' implicit_base = 'https://example.com/cb#access_token=2YotnFZFEjr1zCsicMWpAA&scope=abc&' - implicit_response = implicit_base + 'state={0}&token_type=example&expires_in=3600'.format(state) - implicit_notype = implicit_base + 'state={0}&expires_in=3600'.format(state) - implicit_wrongstate = implicit_base + 'state={0}&token_type=exampleexpires_in=3600'.format('invalid') + implicit_response = implicit_base + 'state={}&token_type=example&expires_in=3600'.format(state) + implicit_notype = implicit_base + 'state={}&expires_in=3600'.format(state) + implicit_wrongstate = implicit_base + 'state={}&token_type=exampleexpires_in=3600'.format('invalid') implicit_nostate = implicit_base + 'token_type=example&expires_in=3600' implicit_notoken = 'https://example.com/cb#state=xyz&token_type=example&expires_in=3600' @@ -244,7 +242,7 @@ class ParameterTests(TestCase): for scope in new + old: self.assertIn(scope, message) self.assertEqual(old, ['aaa']) - self.assertEqual(set(new), set(['abc', 'def'])) + self.assertEqual(set(new), {'abc', 'def'}) finally: signals.scope_changed.disconnect(record_scope_change) del os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] @@ -278,7 +276,7 @@ class ParameterTests(TestCase): for scope in new + old: self.assertIn(scope, message) self.assertEqual(old, ['aaa']) - self.assertEqual(set(new), set(['abc', 'def'])) + self.assertEqual(set(new), {'abc', 'def'}) finally: signals.scope_changed.disconnect(record_scope_change) del os.environ['OAUTHLIB_RELAX_TOKEN_SCOPE'] diff --git a/tests/oauth2/rfc6749/test_request_validator.py b/tests/oauth2/rfc6749/test_request_validator.py index 9dde814..257280c 100644 --- a/tests/oauth2/rfc6749/test_request_validator.py +++ b/tests/oauth2/rfc6749/test_request_validator.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - from oauthlib.oauth2 import RequestValidator from ...unittest import TestCase diff --git a/tests/oauth2/rfc6749/test_server.py b/tests/oauth2/rfc6749/test_server.py index 2c6ecff..9288e49 100644 --- a/tests/oauth2/rfc6749/test_server.py +++ b/tests/oauth2/rfc6749/test_server.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import json import mock @@ -73,7 +71,7 @@ class AuthorizationEndpointTest(TestCase): uri, scopes=['all', 'of', 'them']) self.assertIn('Location', headers) self.assertURLEqual(headers['Location'], 'http://back.to/me?state=xyz', parse_fragment=True) - self.assertEqual(body, None) + self.assertIsNone(body) self.assertEqual(status_code, 302) # and without the state parameter @@ -83,7 +81,7 @@ class AuthorizationEndpointTest(TestCase): uri, scopes=['all', 'of', 'them']) self.assertIn('Location', headers) self.assertURLEqual(headers['Location'], 'http://back.to/me', parse_fragment=True) - self.assertEqual(body, None) + self.assertIsNone(body) self.assertEqual(status_code, 302) def test_missing_type(self): diff --git a/tests/oauth2/rfc6749/test_tokens.py b/tests/oauth2/rfc6749/test_tokens.py index e6f49b1..61a23cb 100644 --- a/tests/oauth2/rfc6749/test_tokens.py +++ b/tests/oauth2/rfc6749/test_tokens.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import, unicode_literals - import mock from oauthlib.common import Request diff --git a/tests/oauth2/rfc6749/test_utils.py b/tests/oauth2/rfc6749/test_utils.py index 609162c..cfc6c2c 100644 --- a/tests/oauth2/rfc6749/test_utils.py +++ b/tests/oauth2/rfc6749/test_utils.py @@ -1,9 +1,6 @@ -from __future__ import absolute_import, unicode_literals - import datetime import os -from oauthlib.common import PY3 from oauthlib.oauth2.rfc6749.utils import (escape, generate_age, host_from_uri, is_secure_transport, list_to_scope, params_from_uri, scope_to_list) @@ -19,12 +16,8 @@ class ScopeObject: def __init__(self, scope): self.scope = scope - if PY3: - def __str__(self): - return self.scope - else: - def __unicode__(self): - return self.scope + def __str__(self): + return self.scope class UtilsTests(TestCase): |