From ba79a477076ed9848b7f32735b9a83fc98b24b4b Mon Sep 17 00:00:00 2001 From: Mathieu Leplatre Date: Thu, 21 Oct 2021 17:40:54 +0200 Subject: [PATCH] Use assertEqual() --- pyramid_multiauth/tests.py | 122 ++++++++++++++++++------------------- 1 file changed, 61 insertions(+), 61 deletions(-) diff --git a/pyramid_multiauth/tests.py b/pyramid_multiauth/tests.py index ddc3d54..84e9ad1 100644 --- a/pyramid_multiauth/tests.py +++ b/pyramid_multiauth/tests.py @@ -166,10 +166,10 @@ def test_basic_stacking(self): policies = [TestAuthnPolicy1(), TestAuthnPolicy2()] policy = MultiAuthenticationPolicy(policies) request = DummyRequest() - self.assertEquals(policy.authenticated_userid(request), - "test2") - self.assertEquals(sorted(policy.effective_principals(request)), - [Authenticated, Everyone, "test1", "test2"]) + self.assertEqual(policy.authenticated_userid(request), + "test2") + self.assertEqual(sorted(policy.effective_principals(request)), + [Authenticated, Everyone, "test1", "test2"]) def test_policy_selected_event(self): from pyramid.testing import testConfig @@ -190,104 +190,104 @@ def track_policy(event): config.add_subscriber(track_policy, MultiAuthPolicySelected) - self.assertEquals(policy.authenticated_userid(request), "test2") + self.assertEqual(policy.authenticated_userid(request), "test2") - self.assertEquals(selected_policy[0].policy, policies[0]) - self.assertEquals(selected_policy[0].policy_name, "name") - self.assertEquals(selected_policy[0].userid, "test2") - self.assertEquals(selected_policy[0].request, request) - self.assertEquals(len(selected_policy), 1) + self.assertEqual(selected_policy[0].policy, policies[0]) + self.assertEqual(selected_policy[0].policy_name, "name") + self.assertEqual(selected_policy[0].userid, "test2") + self.assertEqual(selected_policy[0].request, request) + self.assertEqual(len(selected_policy), 1) # Effective principals also triggers an event when groupfinder # is provided. policy_with_group = MultiAuthenticationPolicy(policies, lambda u, r: ['foo']) policy_with_group.effective_principals(request) - self.assertEquals(len(selected_policy), 2) + self.assertEqual(len(selected_policy), 2) def test_stacking_of_unauthenticated_userid(self): policies = [TestAuthnPolicy2(), TestAuthnPolicy3()] policy = MultiAuthenticationPolicy(policies) request = DummyRequest() - self.assertEquals(policy.unauthenticated_userid(request), "test2") + self.assertEqual(policy.unauthenticated_userid(request), "test2") policies.reverse() - self.assertEquals(policy.unauthenticated_userid(request), "test3") + self.assertEqual(policy.unauthenticated_userid(request), "test3") def test_stacking_of_authenticated_userid(self): policies = [TestAuthnPolicy2(), TestAuthnPolicy3()] policy = MultiAuthenticationPolicy(policies) request = DummyRequest() - self.assertEquals(policy.authenticated_userid(request), "test2") + self.assertEqual(policy.authenticated_userid(request), "test2") policies.reverse() - self.assertEquals(policy.authenticated_userid(request), "test3") + self.assertEqual(policy.authenticated_userid(request), "test3") def test_stacking_of_authenticated_userid_with_groupdfinder(self): policies = [TestAuthnPolicy2(), TestAuthnPolicy3()] policy = MultiAuthenticationPolicy(policies, testgroupfinder) request = DummyRequest() - self.assertEquals(policy.authenticated_userid(request), "test3") + self.assertEqual(policy.authenticated_userid(request), "test3") policies.reverse() - self.assertEquals(policy.unauthenticated_userid(request), "test3") + self.assertEqual(policy.unauthenticated_userid(request), "test3") def test_only_unauthenticated_userid_with_groupfinder(self): policies = [TestAuthnPolicyUnauthOnly()] policy = MultiAuthenticationPolicy(policies, testgroupfinder) request = DummyRequest() - self.assertEquals(policy.unauthenticated_userid(request), "test3") - self.assertEquals(policy.authenticated_userid(request), None) - self.assertEquals(policy.effective_principals(request), [Everyone]) + self.assertEqual(policy.unauthenticated_userid(request), "test3") + self.assertEqual(policy.authenticated_userid(request), None) + self.assertEqual(policy.effective_principals(request), [Everyone]) def test_authenticated_userid_unauthenticated_with_groupfinder(self): policies = [TestAuthnPolicy2()] policy = MultiAuthenticationPolicy(policies, testgroupfinder) request = DummyRequest() - self.assertEquals(policy.authenticated_userid(request), None) - self.assertEquals(sorted(policy.effective_principals(request)), - [Everyone, 'test2']) + self.assertEqual(policy.authenticated_userid(request), None) + self.assertEqual(sorted(policy.effective_principals(request)), + [Everyone, 'test2']) def test_stacking_of_effective_principals(self): policies = [TestAuthnPolicy2(), TestAuthnPolicy3()] policy = MultiAuthenticationPolicy(policies) request = DummyRequest() - self.assertEquals(sorted(policy.effective_principals(request)), - [Authenticated, Everyone, "test2", "test3", "test4"]) + self.assertEqual(sorted(policy.effective_principals(request)), + [Authenticated, Everyone, "test2", "test3", "test4"]) policies.reverse() - self.assertEquals(sorted(policy.effective_principals(request)), - [Authenticated, Everyone, "test2", "test3", "test4"]) + self.assertEqual(sorted(policy.effective_principals(request)), + [Authenticated, Everyone, "test2", "test3", "test4"]) policies.append(TestAuthnPolicy1()) - self.assertEquals(sorted(policy.effective_principals(request)), - [Authenticated, Everyone, "test1", "test2", - "test3", "test4"]) + self.assertEqual(sorted(policy.effective_principals(request)), + [Authenticated, Everyone, "test1", "test2", + "test3", "test4"]) def test_stacking_of_effective_principals_with_groupfinder(self): policies = [TestAuthnPolicy2(), TestAuthnPolicy3()] policy = MultiAuthenticationPolicy(policies, testgroupfinder) request = DummyRequest() - self.assertEquals(sorted(policy.effective_principals(request)), - ["group", Authenticated, Everyone, "test2", - "test3", "test4"]) + self.assertEqual(sorted(policy.effective_principals(request)), + ["group", Authenticated, Everyone, "test2", + "test3", "test4"]) policies.reverse() - self.assertEquals(sorted(policy.effective_principals(request)), - ["group", Authenticated, Everyone, "test2", - "test3", "test4"]) + self.assertEqual(sorted(policy.effective_principals(request)), + ["group", Authenticated, Everyone, "test2", + "test3", "test4"]) policies.append(TestAuthnPolicy1()) - self.assertEquals(sorted(policy.effective_principals(request)), - ["group", Authenticated, Everyone, "test1", - "test2", "test3", "test4"]) + self.assertEqual(sorted(policy.effective_principals(request)), + ["group", Authenticated, Everyone, "test1", + "test2", "test3", "test4"]) def test_stacking_of_remember_and_forget(self): policies = [TestAuthnPolicy1(), TestAuthnPolicy2(), TestAuthnPolicy3()] policy = MultiAuthenticationPolicy(policies) request = DummyRequest() - self.assertEquals(policy.remember(request, "ha"), - [("X-Remember", "ha"), ("X-Remember-2", "ha")]) - self.assertEquals(policy.forget(request), - [("X-Forget", "foo"), ("X-Forget", "bar")]) + self.assertEqual(policy.remember(request, "ha"), + [("X-Remember", "ha"), ("X-Remember-2", "ha")]) + self.assertEqual(policy.forget(request), + [("X-Forget", "foo"), ("X-Forget", "bar")]) policies.reverse() - self.assertEquals(policy.remember(request, "ha"), - [("X-Remember-2", "ha"), ("X-Remember", "ha")]) - self.assertEquals(policy.forget(request), - [("X-Forget", "bar"), ("X-Forget", "foo")]) + self.assertEqual(policy.remember(request, "ha"), + [("X-Remember-2", "ha"), ("X-Remember", "ha")]) + self.assertEqual(policy.forget(request), + [("X-Forget", "bar"), ("X-Forget", "foo")]) def test_includeme_uses_acl_authorization_by_default(self): self.config.include("pyramid_multiauth") @@ -317,12 +317,12 @@ def test_includeme_by_module(self): self.config.include("pyramid_multiauth") self.config.commit() policy = self.config.registry.getUtility(IAuthenticationPolicy) - self.assertEquals(policy._callback, testgroupfinder) - self.assertEquals(len(policy._policies), 3) + self.assertEqual(policy._callback, testgroupfinder) + self.assertEqual(len(policy._policies), 3) # Check that they stack correctly. request = DummyRequest() - self.assertEquals(policy.unauthenticated_userid(request), "test2") - self.assertEquals(policy.authenticated_userid(request), "test3") + self.assertEqual(policy.unauthenticated_userid(request), "test2") + self.assertEqual(policy.authenticated_userid(request), "test3") # Check that the forbidden view gets invoked. self.config.add_route("index", path="/") self.config.add_view(raiseforbidden, route_name="index") @@ -333,7 +333,7 @@ def start_response(*args): pass result = b"".join(app(environ, start_response)) - self.assertEquals(result, b'"FORBIDDEN ONE"') + self.assertEqual(result, b'"FORBIDDEN ONE"') def test_includeme_by_callable(self): self.config.add_settings({ @@ -351,13 +351,13 @@ def test_includeme_by_callable(self): self.config.include("pyramid_multiauth") self.config.commit() policy = self.config.registry.getUtility(IAuthenticationPolicy) - self.assertEquals(policy._callback, testgroupfinder) - self.assertEquals(len(policy._policies), 3) - self.assertEquals(policy._policies[1].foo, "bar") + self.assertEqual(policy._callback, testgroupfinder) + self.assertEqual(len(policy._policies), 3) + self.assertEqual(policy._policies[1].foo, "bar") # Check that they stack correctly. request = DummyRequest() - self.assertEquals(policy.unauthenticated_userid(request), "test2") - self.assertEquals(policy.authenticated_userid(request), "test3") + self.assertEqual(policy.unauthenticated_userid(request), "test2") + self.assertEqual(policy.authenticated_userid(request), "test3") # Check that the forbidden view gets invoked. self.config.add_route("index", path="/") self.config.add_view(raiseforbidden, route_name="index") @@ -368,7 +368,7 @@ def start_response(*args): pass result = b"".join(app(environ, start_response)) - self.assertEquals(result, b'"FORBIDDEN ONE"') + self.assertEqual(result, b'"FORBIDDEN ONE"') def test_includeme_with_unconfigured_policy(self): self.config.add_settings({ @@ -402,7 +402,7 @@ def test_get_policy(self): TestAuthnPolicy2)) self.assertTrue(isinstance(policy.get_policy("policy2"), TestAuthnPolicy3)) - self.assertEquals(policy.get_policy("policy3"), None) + self.assertEqual(policy.get_policy("policy3"), None) # Test getting policies by class. self.assertTrue(isinstance(policy.get_policy(TestAuthnPolicy1), TestAuthnPolicy1)) @@ -410,7 +410,7 @@ def test_get_policy(self): TestAuthnPolicy2)) self.assertTrue(isinstance(policy.get_policy(TestAuthnPolicy3), TestAuthnPolicy3)) - self.assertEquals(policy.get_policy(MultiAuthPolicyTests), None) + self.assertEqual(policy.get_policy(MultiAuthPolicyTests), None) def test_get_policies(self): self.config.add_settings({ @@ -431,5 +431,5 @@ def test_get_policies(self): ("policy2", TestAuthnPolicy3), ] for (obtained, expected) in zip(policies, expected_result): - self.assertEquals(obtained[0], expected[0]) + self.assertEqual(obtained[0], expected[0]) self.assertTrue(isinstance(obtained[1], expected[1]))