Skip to content

Commit

Permalink
Use assertEqual()
Browse files Browse the repository at this point in the history
  • Loading branch information
leplatrem committed Oct 26, 2021
1 parent 547e34f commit ba79a47
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions pyramid_multiauth/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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({
Expand All @@ -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")
Expand All @@ -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({
Expand Down Expand Up @@ -402,15 +402,15 @@ 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))
self.assertTrue(isinstance(policy.get_policy(TestAuthnPolicy2),
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({
Expand All @@ -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]))

0 comments on commit ba79a47

Please sign in to comment.