From f934ecbc207f2643326f3de0f36fee1d19a286ae Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Wed, 22 Dec 2021 14:35:18 +0000 Subject: [PATCH 1/2] Use assertRaisesRegex instead of assertRaisesRegexp for Python 3.11 compatibility. --- tests/test_client.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index b180c6b8..7d1e5e89 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -190,11 +190,12 @@ def test_auth_code_flow(self): self.assertLoosely(result, lambda: self.assertIn('access_token', result)) def test_auth_code_flow_error_response(self): - with self.assertRaisesRegexp(ValueError, "state missing"): + assertRaisesRegex = getattr(self, "assertRaisesRegex", self.assertRaisesRegexp) + with assertRaisesRegex(ValueError, "state missing"): self.client.obtain_token_by_auth_code_flow({}, {"code": "foo"}) - with self.assertRaisesRegexp(ValueError, "state mismatch"): + with assertRaisesRegex(ValueError, "state mismatch"): self.client.obtain_token_by_auth_code_flow({"state": "1"}, {"state": "2"}) - with self.assertRaisesRegexp(ValueError, "scope"): + with assertRaisesRegex(ValueError, "scope"): self.client.obtain_token_by_auth_code_flow( {"state": "s", "scope": ["foo"]}, {"state": "s"}, scope=["bar"]) self.assertEqual( From c38af0193638bf9a28527dbd70726eee53811183 Mon Sep 17 00:00:00 2001 From: Karthikeyan Singaravelan Date: Wed, 29 Dec 2021 04:46:36 +0000 Subject: [PATCH 2/2] Fix Python 2.7 compatibility. --- tests/test_authority.py | 6 +++++- tests/test_client.py | 12 ++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/test_authority.py b/tests/test_authority.py index 9fdc83c5..43b3a67b 100644 --- a/tests/test_authority.py +++ b/tests/test_authority.py @@ -52,7 +52,11 @@ def test_lessknown_host_will_return_a_set_of_v1_endpoints(self): self.assertNotIn('v2.0', a.token_endpoint) def test_unknown_host_wont_pass_instance_discovery(self): - _assert = getattr(self, "assertRaisesRegex", self.assertRaisesRegexp) # Hack + if hasattr(self, "assertRaisesRegex"): + _assert = self.assertRaisesRegex + else: + _assert = self.assertRaisesRegexp + with _assert(ValueError, "invalid_instance"): Authority('https://example.com/tenant_doesnt_matter_in_this_case', MinimalHttpClient()) diff --git a/tests/test_client.py b/tests/test_client.py index 7d1e5e89..1342d29e 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -190,12 +190,16 @@ def test_auth_code_flow(self): self.assertLoosely(result, lambda: self.assertIn('access_token', result)) def test_auth_code_flow_error_response(self): - assertRaisesRegex = getattr(self, "assertRaisesRegex", self.assertRaisesRegexp) - with assertRaisesRegex(ValueError, "state missing"): + if hasattr(self, "assertRaisesRegex"): + _assert = self.assertRaisesRegex + else: + _assert = self.assertRaisesRegexp + + with _assert(ValueError, "state missing"): self.client.obtain_token_by_auth_code_flow({}, {"code": "foo"}) - with assertRaisesRegex(ValueError, "state mismatch"): + with _assert(ValueError, "state mismatch"): self.client.obtain_token_by_auth_code_flow({"state": "1"}, {"state": "2"}) - with assertRaisesRegex(ValueError, "scope"): + with _assert(ValueError, "scope"): self.client.obtain_token_by_auth_code_flow( {"state": "s", "scope": ["foo"]}, {"state": "s"}, scope=["bar"]) self.assertEqual(