From 5c54f25750a2a7ce5dba11d6088d0a6ae6f57f47 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Fri, 28 Dec 2018 08:15:07 -0500 Subject: [PATCH] Remove testing workarounds for Python 2.6 Python 2.6 has not been supported since 84ad78ca24e323669a6ceea989390fd7ed9a11bf in the v1.0.0 release. --- tests/test_oauth1_session.py | 26 +++++--------------------- tests/test_oauth2_session.py | 4 ---- 2 files changed, 5 insertions(+), 25 deletions(-) diff --git a/tests/test_oauth1_session.py b/tests/test_oauth1_session.py index 45050d8a..4bdf3a8e 100644 --- a/tests/test_oauth1_session.py +++ b/tests/test_oauth1_session.py @@ -62,12 +62,6 @@ class OAuth1SessionTest(unittest.TestCase): - - def setUp(self): - # For python 2.6 - if not hasattr(self, 'assertIn'): - self.assertIn = lambda a, b: self.assertTrue(a in b) - def test_signature_types(self): def verify_signature(getter): def fake_send(r, **kwargs): @@ -204,14 +198,9 @@ def _test_fetch_access_token_raises_error(self, auth): passed in to the client. """ auth.send = self.fake_body('oauth_token=foo') - - # Use a try-except block so that we can assert on the exception message - # being raised and also keep the Python2.6 compatibility where - # assertRaises is not a context manager. - try: + with self.assertRaises(ValueError) as cm: auth.fetch_access_token('https://example.com/token') - except ValueError as exc: - self.assertEqual('No client verifier has been set.', str(exc)) + self.assertEqual('No client verifier has been set.', str(cm.exception)) def test_fetch_token_invalid_response(self): auth = OAuth1Session('foo') @@ -221,15 +210,10 @@ def test_fetch_token_invalid_response(self): for code in (400, 401, 403): auth.send = self.fake_body('valid=response', code) - # use try/catch rather than self.assertRaises, so we can - # assert on the properties of the exception - try: + with self.assertRaises(ValueError) as cm: auth.fetch_request_token('https://example.com/token') - except ValueError as err: - self.assertEqual(err.status_code, code) - self.assertTrue(isinstance(err.response, requests.Response)) - else: # no exception raised - self.fail("ValueError not raised") + self.assertEqual(cm.exception.status_code, code) + self.assertIsInstance(cm.exception.response, requests.Response) def test_fetch_access_token_missing_verifier(self): self._test_fetch_access_token_raises_error(OAuth1Session('foo')) diff --git a/tests/test_oauth2_session.py b/tests/test_oauth2_session.py index e5892cab..f499508e 100644 --- a/tests/test_oauth2_session.py +++ b/tests/test_oauth2_session.py @@ -29,10 +29,6 @@ def fake_send(r, **kwargs): class OAuth2SessionTest(TestCase): def setUp(self): - # For python 2.6 - if not hasattr(self, 'assertIn'): - self.assertIn = lambda a, b: self.assertTrue(a in b) - self.token = { 'token_type': 'Bearer', 'access_token': 'asdfoiw37850234lkjsdfsdf',