예제 #1
0
 def test_get_least_permissions_aces_not_allowed(self, mock_meth):
     request = Mock()
     request.has_permission.return_value = False
     acl = polymorphic.PolymorphicACL(request)
     resource = Mock()
     resource.view._factory = Mock()
     assert acl._get_least_permissions_aces([resource]) is None
     resource.view._factory.assert_called_once_with(request)
     request.has_permission.assert_called_once_with(
         'view', resource.view._factory())
예제 #2
0
 def test_set_collections_acl_no_aces(self, mock_coll, mock_res, mock_aces):
     from pyramid.security import DENY_ALL
     mock_coll.return_value = ['stories', 'users']
     mock_res.return_value = ['foo', 'bar']
     mock_aces.return_value = None
     acl = polymorphic.PolymorphicACL(None)
     assert len(acl.__acl__) == 2
     assert DENY_ALL == acl.__acl__[-1]
     mock_coll.assert_called_once_with()
     mock_res.assert_called_once_with(['stories', 'users'])
     mock_aces.assert_called_once_with(['foo', 'bar'])
예제 #3
0
 def test_set_collections_acl_has_aces(self, mock_coll, mock_res,
                                       mock_aces):
     from pyramid.security import Allow, DENY_ALL
     aces = [(Allow, 'foobar', 'dostuff')]
     mock_aces.return_value = aces
     acl = polymorphic.PolymorphicACL(None)
     assert len(acl.__acl__) == 3
     assert DENY_ALL == acl.__acl__[-1]
     assert aces[0] in acl.__acl__
     assert mock_coll.call_count == 1
     assert mock_res.call_count == 1
     assert mock_aces.call_count == 1
예제 #4
0
 def test_get_least_permissions_aces_allowed(self, mock_meth):
     from pyramid.security import Allow
     request = Mock()
     request.has_permission.return_value = True
     request.effective_principals = ['user', 'admin']
     acl = polymorphic.PolymorphicACL(request)
     resource = Mock()
     resource.view._factory = Mock()
     aces = acl._get_least_permissions_aces([resource])
     resource.view._factory.assert_called_once_with(request)
     request.has_permission.assert_called_once_with(
         'view', resource.view._factory())
     assert len(aces) == 2
     assert (Allow, 'user', 'view') in aces
     assert (Allow, 'admin', 'view') in aces
예제 #5
0
 def test_init(self, mock_meth):
     polymorphic.PolymorphicACL(None)
     mock_meth.assert_called_once_with()