summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTheron Luhn <theron@luhn.com>2019-03-09 12:39:41 -0800
committerTheron Luhn <theron@luhn.com>2019-03-09 13:40:17 -0800
commit027d3cbd461be0555e7f4e44b508428228a4b56f (patch)
treec6299b875e81a5feade9634c41d14a2453a5e383 /tests
parentedf7ef0c379361f3a056014b068a01657decfb76 (diff)
downloadpyramid-027d3cbd461be0555e7f4e44b508428228a4b56f.tar.gz
pyramid-027d3cbd461be0555e7f4e44b508428228a4b56f.tar.bz2
pyramid-027d3cbd461be0555e7f4e44b508428228a4b56f.zip
Revamp tests for EffectivePrincipalsPredicate.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_predicates.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/tests/test_predicates.py b/tests/test_predicates.py
index a99651a8f..60e36047e 100644
--- a/tests/test_predicates.py
+++ b/tests/test_predicates.py
@@ -502,6 +502,22 @@ class Test_EffectivePrincipalsPredicate(unittest.TestCase):
return EffectivePrincipalsPredicate(val, config)
+ def _testing_authn_policy(self, userid, groupids=tuple()):
+ from pyramid.interfaces import IAuthenticationPolicy
+ from pyramid.security import Everyone, Authenticated
+
+ class DummyPolicy:
+ def effective_principals(self, request):
+ p = [Everyone]
+ if userid:
+ p.append(Authenticated)
+ p.append(userid)
+ p.extend(groupids)
+ return p
+
+ registry = self.config.registry
+ registry.registerUtility(DummyPolicy(), IAuthenticationPolicy)
+
def test_text(self):
inst = self._makeOne(('verna', 'fred'), None)
self.assertEqual(
@@ -526,7 +542,7 @@ class Test_EffectivePrincipalsPredicate(unittest.TestCase):
def test_it_call_authentication_policy_provides_superset(self):
request = testing.DummyRequest()
- self.config.testing_securitypolicy('fred', groupids=('verna', 'bambi'))
+ self._testing_authn_policy('fred', groupids=('verna', 'bambi'))
inst = self._makeOne(('verna', 'fred'), None)
context = Dummy()
self.assertTrue(inst(context, request))
@@ -535,14 +551,14 @@ class Test_EffectivePrincipalsPredicate(unittest.TestCase):
from pyramid.security import Authenticated
request = testing.DummyRequest()
- self.config.testing_securitypolicy('fred', groupids=('verna', 'bambi'))
+ self._testing_authn_policy('fred', groupids=('verna', 'bambi'))
inst = self._makeOne(Authenticated, None)
context = Dummy()
self.assertTrue(inst(context, request))
def test_it_call_authentication_policy_doesnt_provide_superset(self):
request = testing.DummyRequest()
- self.config.testing_securitypolicy('fred')
+ self._testing_authn_policy('fred')
inst = self._makeOne(('verna', 'fred'), None)
context = Dummy()
self.assertFalse(inst(context, request))