summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2017-06-08 23:59:34 -0500
committerGitHub <noreply@github.com>2017-06-08 23:59:34 -0500
commit5da7f5b0514e4753a6f6192d27bb237a4c338b9f (patch)
tree23cf28570da3825e3029683bce3c9a96f5776d53
parentdaf06d8f8dbfa3245ea4de28defc0249219b6b0e (diff)
parent1814cda1f5ec85c24651bfd29645e4057ae5200e (diff)
downloadpyramid-5da7f5b0514e4753a6f6192d27bb237a4c338b9f.tar.gz
pyramid-5da7f5b0514e4753a6f6192d27bb237a4c338b9f.tar.bz2
pyramid-5da7f5b0514e4753a6f6192d27bb237a4c338b9f.zip
Merge pull request #3074 from Pylons/3073-all_permissions_list-iterability
Ensure that instances of 'AllPermissionsList' are iterable.
-rw-r--r--pyramid/security.py5
-rw-r--r--pyramid/tests/test_security.py24
2 files changed, 26 insertions, 3 deletions
diff --git a/pyramid/security.py b/pyramid/security.py
index 82e6b73a9..035f09f77 100644
--- a/pyramid/security.py
+++ b/pyramid/security.py
@@ -21,10 +21,13 @@ _marker = object()
class AllPermissionsList(object):
""" Stand in 'permission list' to represent all permissions """
+
def __iter__(self):
- return ()
+ return iter(())
+
def __contains__(self, other):
return True
+
def __eq__(self, other):
return isinstance(other, self.__class__)
diff --git a/pyramid/tests/test_security.py b/pyramid/tests/test_security.py
index 6d75ac8e3..5561a05d7 100644
--- a/pyramid/tests/test_security.py
+++ b/pyramid/tests/test_security.py
@@ -16,12 +16,32 @@ class TestAllPermissionsList(unittest.TestCase):
def _makeOne(self):
return self._getTargetClass()()
- def test_it(self):
+ def test_equality_w_self(self):
thing = self._makeOne()
self.assertTrue(thing.__eq__(thing))
- self.assertEqual(thing.__iter__(), ())
+
+ def test_equality_w_other_instances_of_class(self):
+ thing = self._makeOne()
+ other = self._makeOne()
+ self.assertTrue(thing.__eq__(other))
+
+ def test_equality_miss(self):
+ thing = self._makeOne()
+ other = object()
+ self.assertFalse(thing.__eq__(other))
+
+ def test_contains_w_string(self):
+ thing = self._makeOne()
self.assertTrue('anything' in thing)
+ def test_contains_w_object(self):
+ thing = self._makeOne()
+ self.assertTrue(object() in thing)
+
+ def test_iterable(self):
+ thing = self._makeOne()
+ self.assertEqual(list(thing), [])
+
def test_singleton(self):
from pyramid.security import ALL_PERMISSIONS
self.assertEqual(ALL_PERMISSIONS.__class__, self._getTargetClass())