def test_set_and_get_acl(self, db_session): from kotti import DBSession from kotti.resources import get_root root = get_root() # The __acl__ attribute of Nodes allows access to the mapped # '_acl' property: del root.__acl__ with raises(AttributeError): root._get_acl() root.__acl__ = [('Allow', 'system.Authenticated', ['edit'])] assert ( root.__acl__ == [('Allow', 'system.Authenticated', ['edit'])]) root.__acl__ = [ ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ] assert ( root.__acl__ == [ ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ]) # We can append to the ACL, and it'll be persisted fine: root.__acl__.append(('Allow', 'system.Authenticated', ['edit'])) assert ( root.__acl__ == [ ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['edit']), ]) DBSession.flush() DBSession.expire_all() assert ( root.__acl__ == [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['edit']), ])
def test_nested_annotations_mutable(self): from kotti import DBSession from kotti.resources import get_root root = get_root() root.annotations['foo'] = {} DBSession.flush() DBSession.expire_all() root = get_root() root.annotations['foo']['bar'] = u'baz' self.assertTrue(root in DBSession.dirty) DBSession.flush() DBSession.expire_all() root = get_root() self.assertEqual(root.annotations['foo']['bar'], u'baz')
def test_nested_annotations_mutable(self, db_session): from kotti import DBSession from kotti.resources import get_root root = get_root() root.annotations['foo'] = {} DBSession.flush() DBSession.expire_all() root = get_root() root.annotations['foo']['bar'] = u'baz' assert root in DBSession.dirty DBSession.flush() DBSession.expire_all() root = get_root() assert root.annotations['foo']['bar'] == u'baz'
def test_set_and_get_acl(self): from kotti import DBSession from kotti.resources import get_root root = get_root() # The __acl__ attribute of Nodes allows access to the mapped # '_acl' property: del root.__acl__ self.assertRaises(AttributeError, root._get_acl) root.__acl__ = [('Allow', 'system.Authenticated', ['edit'])] self.assertEquals( root.__acl__, [('Allow', 'system.Authenticated', ['edit'])]) root.__acl__ = [ ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ] self.assertEquals( root.__acl__, [ ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ]) # We can append to the ACL, and it'll be persisted fine: root.__acl__.append(('Allow', 'system.Authenticated', ['edit'])) self.assertEquals( root.__acl__, [ ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['edit']), ]) DBSession.flush() DBSession.expire_all() self.assertEquals( root.__acl__, [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['edit']), ])
def test_set_and_get_acl(self): from kotti import DBSession from kotti.resources import get_root root = get_root() # The __acl__ attribute of Nodes allows access to the mapped # '_acl' property: del root.__acl__ self.assertRaises(AttributeError, root._get_acl) root.__acl__ = [['Allow', 'system.Authenticated', ['edit']]] self.assertEquals( root.__acl__, [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['edit']), ]) root.__acl__ = [ ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ] self.assertEquals( root.__acl__, [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ]) # We can reorder the ACL: first, second = root.__acl__[1:] root.__acl__ = [second, first] self.assertEquals( root.__acl__, [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['view']), ]) DBSession.flush() DBSession.expire_all() self.assertEquals(root.__acl__[1:], [second, first]) root._del_acl() self.assertRaises(AttributeError, root._del_acl)
def test_set_and_get_acl(self): from kotti import DBSession from kotti.resources import get_root root = get_root() # The __acl__ attribute of Nodes allows access to the mapped # '_acl' property: del root.__acl__ self.assertRaises(AttributeError, root._get_acl) root.__acl__ = [['Allow', 'system.Authenticated', ['edit']]] self.assertEquals(root.__acl__, [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['edit']), ]) root.__acl__ = [ ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ] self.assertEquals(root.__acl__, [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['view']), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ]) # We can reorder the ACL: first, second = root.__acl__[1:] root.__acl__ = [second, first] self.assertEquals(root.__acl__, [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Deny', 'system.Authenticated', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['view']), ]) DBSession.flush() DBSession.expire_all() self.assertEquals(root.__acl__[1:], [second, first]) root._del_acl() self.assertRaises(AttributeError, root._del_acl)
def test_append_to_empty_acl(self, db_session): from kotti import DBSession from kotti.resources import get_root from kotti.resources import Node root = get_root() node = root['child'] = Node() node.__acl__ = [] DBSession.flush() DBSession.expire_all() node.__acl__.append(('Allow', 'system.Authenticated', ['edit'])) DBSession.flush() DBSession.expire_all() assert node.__acl__ == [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['edit']), ]
def test_append_to_empty_acl(self): from kotti import DBSession from kotti.resources import get_root from kotti.resources import Node root = get_root() node = root['child'] = Node() node.__acl__ = [] DBSession.flush() DBSession.expire_all() node.__acl__.append(('Allow', 'system.Authenticated', ['edit'])) DBSession.flush() DBSession.expire_all() assert node.__acl__ == [ ('Allow', 'role:admin', ALL_PERMISSIONS), ('Allow', 'system.Authenticated', ['edit']), ]
def expire(event): DBSession.flush() DBSession.expire_all()