Skip to content

Commit

Permalink
Ensure that instances of 'AllPermissionsList' are iterable.
Browse files Browse the repository at this point in the history
Cherry pick 1814cda from master.

Closes #3073.
  • Loading branch information
tseaver committed Jun 6, 2017
1 parent c8f5b7d commit f70edbe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
5 changes: 4 additions & 1 deletion pyramid/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@

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__)

Expand Down
24 changes: 22 additions & 2 deletions pyramid/tests/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,32 @@ def _getTargetClass(self):
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())
Expand Down

0 comments on commit f70edbe

Please sign in to comment.