diff options
author | Hugo <hugovk@users.noreply.github.com> | 2019-08-14 23:35:36 +0300 |
---|---|---|
committer | Hugo <hugovk@users.noreply.github.com> | 2019-08-15 12:24:33 +0300 |
commit | 3718a0e048e64994c2ee3819c5e5ed218a05f115 (patch) | |
tree | 38b56eba3e23b5c20af0a09a6a860ecc279dc067 /tests | |
parent | ddc953c11e8d79607f5931a2f80dcd9f7a10c5d9 (diff) | |
download | oauthlib-3718a0e048e64994c2ee3819c5e5ed218a05f115.tar.gz |
Drop support for legacy Python 2.7
Diffstat (limited to 'tests')
-rw-r--r-- | tests/oauth1/rfc5849/test_signatures.py | 3 | ||||
-rw-r--r-- | tests/oauth1/rfc5849/test_utils.py | 9 | ||||
-rw-r--r-- | tests/oauth2/rfc6749/endpoints/test_scope_handling.py | 6 | ||||
-rw-r--r-- | tests/oauth2/rfc6749/test_utils.py | 9 | ||||
-rw-r--r-- | tests/test_common.py | 50 | ||||
-rw-r--r-- | tests/unittest/__init__.py | 21 |
6 files changed, 41 insertions, 57 deletions
diff --git a/tests/oauth1/rfc5849/test_signatures.py b/tests/oauth1/rfc5849/test_signatures.py index bb0dc78..4eb7ff3 100644 --- a/tests/oauth1/rfc5849/test_signatures.py +++ b/tests/oauth1/rfc5849/test_signatures.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals -from oauthlib.common import unicode_type from oauthlib.oauth1.rfc5849.signature import (collect_parameters, signature_base_string, base_string_uri, @@ -232,7 +231,7 @@ class SignatureTests(TestCase): normalized = normalize_parameters(parameters) # Unicode everywhere and always - self.assertIsInstance(normalized, unicode_type) + self.assertIsInstance(normalized, str) # Lets see if things are in order # check to see that querystring keys come in alphanumeric order: diff --git a/tests/oauth1/rfc5849/test_utils.py b/tests/oauth1/rfc5849/test_utils.py index 5a889e8..1db2659 100644 --- a/tests/oauth1/rfc5849/test_utils.py +++ b/tests/oauth1/rfc5849/test_utils.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals -from oauthlib.common import unicode_type from oauthlib.oauth1.rfc5849.utils import * from ...unittest import TestCase @@ -102,12 +101,12 @@ class UtilsTests(TestCase): def test_escape(self): self.assertRaises(ValueError, escape, b"I am a string type. Not a unicode type.") self.assertEqual(escape("I am a unicode type."), "I%20am%20a%20unicode%20type.") - self.assertIsInstance(escape("I am a unicode type."), unicode_type) + self.assertIsInstance(escape("I am a unicode type."), str) def test_unescape(self): self.assertRaises(ValueError, unescape, b"I am a string type. Not a unicode type.") self.assertEqual(unescape("I%20am%20a%20unicode%20type."), 'I am a unicode type.') - self.assertIsInstance(unescape("I%20am%20a%20unicode%20type."), unicode_type) + self.assertIsInstance(unescape("I%20am%20a%20unicode%20type."), str) def test_parse_authorization_header(self): # make us some headers @@ -122,8 +121,8 @@ class UtilsTests(TestCase): # are the internal components of each tuple unicode? for k, v in authorization_headers: - self.assertIsInstance(k, unicode_type) - self.assertIsInstance(v, unicode_type) + self.assertIsInstance(k, str) + self.assertIsInstance(v, str) # let's check the parsed headers created correct_headers = [ diff --git a/tests/oauth2/rfc6749/endpoints/test_scope_handling.py b/tests/oauth2/rfc6749/endpoints/test_scope_handling.py index 4f27963..b235bd7 100644 --- a/tests/oauth2/rfc6749/endpoints/test_scope_handling.py +++ b/tests/oauth2/rfc6749/endpoints/test_scope_handling.py @@ -65,13 +65,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/test_utils.py b/tests/oauth2/rfc6749/test_utils.py index 609162c..6b85b27 100644 --- a/tests/oauth2/rfc6749/test_utils.py +++ b/tests/oauth2/rfc6749/test_utils.py @@ -3,7 +3,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 +18,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): diff --git a/tests/test_common.py b/tests/test_common.py index ae2531b..c2c5e41 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -8,7 +8,7 @@ import oauthlib from oauthlib.common import (CaseInsensitiveDict, Request, add_params_to_uri, extract_params, generate_client_id, generate_nonce, generate_timestamp, - generate_token, unicode_type, urldecode) + generate_token, urldecode) from .unittest import TestCase @@ -21,23 +21,23 @@ URI = 'http://www.someuri.com' class EncodingTest(TestCase): def test_urldecode(self): - self.assertItemsEqual(urldecode(''), []) - self.assertItemsEqual(urldecode('='), [('', '')]) - self.assertItemsEqual(urldecode('%20'), [(' ', '')]) - self.assertItemsEqual(urldecode('+'), [(' ', '')]) - self.assertItemsEqual(urldecode('c2'), [('c2', '')]) - self.assertItemsEqual(urldecode('c2='), [('c2', '')]) - self.assertItemsEqual(urldecode('foo=bar'), [('foo', 'bar')]) - self.assertItemsEqual(urldecode('foo_%20~=.bar-'), + self.assertCountEqual(urldecode(''), []) + self.assertCountEqual(urldecode('='), [('', '')]) + self.assertCountEqual(urldecode('%20'), [(' ', '')]) + self.assertCountEqual(urldecode('+'), [(' ', '')]) + self.assertCountEqual(urldecode('c2'), [('c2', '')]) + self.assertCountEqual(urldecode('c2='), [('c2', '')]) + self.assertCountEqual(urldecode('foo=bar'), [('foo', 'bar')]) + self.assertCountEqual(urldecode('foo_%20~=.bar-'), [('foo_ ~', '.bar-')]) - self.assertItemsEqual(urldecode('foo=1,2,3'), [('foo', '1,2,3')]) - self.assertItemsEqual(urldecode('foo=(1,2,3)'), [('foo', '(1,2,3)')]) - self.assertItemsEqual(urldecode('foo=bar.*'), [('foo', 'bar.*')]) - self.assertItemsEqual(urldecode('foo=bar@spam'), [('foo', 'bar@spam')]) - self.assertItemsEqual(urldecode('foo=bar/baz'), [('foo', 'bar/baz')]) - self.assertItemsEqual(urldecode('foo=bar?baz'), [('foo', 'bar?baz')]) - self.assertItemsEqual(urldecode('foo=bar\'s'), [('foo', 'bar\'s')]) - self.assertItemsEqual(urldecode('foo=$'), [('foo', '$')]) + self.assertCountEqual(urldecode('foo=1,2,3'), [('foo', '1,2,3')]) + self.assertCountEqual(urldecode('foo=(1,2,3)'), [('foo', '(1,2,3)')]) + self.assertCountEqual(urldecode('foo=bar.*'), [('foo', 'bar.*')]) + self.assertCountEqual(urldecode('foo=bar@spam'), [('foo', 'bar@spam')]) + self.assertCountEqual(urldecode('foo=bar/baz'), [('foo', 'bar/baz')]) + self.assertCountEqual(urldecode('foo=bar?baz'), [('foo', 'bar?baz')]) + self.assertCountEqual(urldecode('foo=bar\'s'), [('foo', 'bar\'s')]) + self.assertCountEqual(urldecode('foo=$'), [('foo', '$')]) self.assertRaises(ValueError, urldecode, 'foo bar') self.assertRaises(ValueError, urldecode, '%R') self.assertRaises(ValueError, urldecode, '%RA') @@ -48,20 +48,20 @@ class EncodingTest(TestCase): class ParameterTest(TestCase): def test_extract_params_dict(self): - self.assertItemsEqual(extract_params(PARAMS_DICT), PARAMS_TWOTUPLE) + self.assertCountEqual(extract_params(PARAMS_DICT), PARAMS_TWOTUPLE) def test_extract_params_twotuple(self): - self.assertItemsEqual(extract_params(PARAMS_TWOTUPLE), PARAMS_TWOTUPLE) + self.assertCountEqual(extract_params(PARAMS_TWOTUPLE), PARAMS_TWOTUPLE) def test_extract_params_formencoded(self): - self.assertItemsEqual(extract_params(PARAMS_FORMENCODED), + self.assertCountEqual(extract_params(PARAMS_FORMENCODED), PARAMS_TWOTUPLE) def test_extract_params_blank_string(self): - self.assertItemsEqual(extract_params(''), []) + self.assertCountEqual(extract_params(''), []) def test_extract_params_empty_list(self): - self.assertItemsEqual(extract_params([]), []) + self.assertCountEqual(extract_params([]), []) def test_extract_non_formencoded_string(self): self.assertEqual(extract_params('not a formencoded string'), None) @@ -80,7 +80,7 @@ class GeneratorTest(TestCase): def test_generate_timestamp(self): timestamp = generate_timestamp() - self.assertIsInstance(timestamp, unicode_type) + self.assertIsInstance(timestamp, str) self.assertTrue(int(timestamp)) self.assertGreater(int(timestamp), 1331672335) @@ -160,11 +160,11 @@ class RequestTest(TestCase): def test_list_body(self): r = Request(URI, body=PARAMS_TWOTUPLE) - self.assertItemsEqual(r.decoded_body, PARAMS_TWOTUPLE) + self.assertCountEqual(r.decoded_body, PARAMS_TWOTUPLE) def test_dict_body(self): r = Request(URI, body=PARAMS_DICT) - self.assertItemsEqual(r.decoded_body, PARAMS_TWOTUPLE) + self.assertCountEqual(r.decoded_body, PARAMS_TWOTUPLE) def test_getattr_existing_attribute(self): r = Request(URI, body='foo bar') diff --git a/tests/unittest/__init__.py b/tests/unittest/__init__.py index 6cb79a6..13ad92f 100644 --- a/tests/unittest/__init__.py +++ b/tests/unittest/__init__.py @@ -1,18 +1,8 @@ -import collections -import sys from unittest import TestCase -try: - import urlparse -except ImportError: - import urllib.parse as urlparse +import urllib.parse as urlparse -# Somewhat consistent itemsequal between all python versions -if sys.version_info[0] == 3: - TestCase.assertItemsEqual = TestCase.assertCountEqual - - -# URL comparison where query param order is insignifcant +# URL comparison where query param order is insignificant def url_equals(self, a, b, parse_fragment=False): parsed_a = urlparse.urlparse(a, allow_fragments=parse_fragment) parsed_b = urlparse.urlparse(b, allow_fragments=parse_fragment) @@ -21,7 +11,7 @@ def url_equals(self, a, b, parse_fragment=False): if parse_fragment: fragment_a = urlparse.parse_qsl(parsed_a.fragment) fragment_b = urlparse.parse_qsl(parsed_b.fragment) - self.assertItemsEqual(fragment_a, fragment_b) + self.assertCountEqual(fragment_a, fragment_b) else: self.assertEqual(parsed_a.fragment, parsed_b.fragment) self.assertEqual(parsed_a.scheme, parsed_b.scheme) @@ -32,10 +22,11 @@ def url_equals(self, a, b, parse_fragment=False): self.assertEqual(parsed_a.password, parsed_b.password) self.assertEqual(parsed_a.hostname, parsed_b.hostname) self.assertEqual(parsed_a.port, parsed_b.port) - self.assertItemsEqual(query_a, query_b) + self.assertCountEqual(query_a, query_b) + TestCase.assertURLEqual = url_equals # Form body comparison where order is insignificant -TestCase.assertFormBodyEqual = lambda self, a, b: self.assertItemsEqual( +TestCase.assertFormBodyEqual = lambda self, a, b: self.assertCountEqual( urlparse.parse_qsl(a), urlparse.parse_qsl(b)) |