Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
session = DBSession()
root = get_root()
child = root[u'child'] = Node()
session.flush()
self.assertEqual(principals_with_local_roles(root), [])
self.assertEqual(principals_with_local_roles(child), [])
self.assertEqual(map_principals_with_local_roles(root), [])
self.assertEqual(map_principals_with_local_roles(child), [])
set_groups('group:bobsgroup', child, ['role:editor'])
set_groups('bob', root, ['group:bobsgroup'])
set_groups('group:franksgroup', root, ['role:editor'])
self.assertEqual(
set(principals_with_local_roles(child)),
set(['bob', 'group:bobsgroup', 'group:franksgroup'])
)
self.assertEqual(
set(principals_with_local_roles(child, inherit=False)),
set(['group:bobsgroup'])
)
self.assertEqual(
set(principals_with_local_roles(root)),
set(['bob', 'group:franksgroup'])
)
)
# We make a copy of 'child', and we expect the local roles to
# be copied over:
child2 = root['child2'] = child.copy()
DBSession.flush()
self.assertEqual(
set(principals_with_local_roles(child2)),
set(['bob', 'group:bobsgroup', 'group:franksgroup'])
)
self.assertEqual(len(principals_with_local_roles(child)), 3)
# When we now change the local roles of 'child', the copy is
# unaffected:
set_groups('group:bobsgroup', child, [])
self.assertEqual(len(principals_with_local_roles(child)), 2)
self.assertEqual(len(principals_with_local_roles(child2)), 3)
self.assertEqual(map_principals_with_local_roles(child), [])
set_groups('group:bobsgroup', child, ['role:editor'])
set_groups('bob', root, ['group:bobsgroup'])
set_groups('group:franksgroup', root, ['role:editor'])
self.assertEqual(
set(principals_with_local_roles(child)),
set(['bob', 'group:bobsgroup', 'group:franksgroup'])
)
self.assertEqual(
set(principals_with_local_roles(child, inherit=False)),
set(['group:bobsgroup'])
)
self.assertEqual(
set(principals_with_local_roles(root)),
set(['bob', 'group:franksgroup'])
)
def test_principals_with_local_roles(self):
session = DBSession()
root = get_root()
child = root[u'child'] = Node()
session.flush()
self.assertEqual(principals_with_local_roles(root), [])
self.assertEqual(principals_with_local_roles(child), [])
self.assertEqual(map_principals_with_local_roles(root), [])
self.assertEqual(map_principals_with_local_roles(child), [])
set_groups('group:bobsgroup', child, ['role:editor'])
set_groups('bob', root, ['group:bobsgroup'])
set_groups('group:franksgroup', root, ['role:editor'])
self.assertEqual(
set(principals_with_local_roles(child)),
set(['bob', 'group:bobsgroup', 'group:franksgroup'])
)
self.assertEqual(
set(principals_with_local_roles(child, inherit=False)),
set(['group:bobsgroup'])
)
self.assertEqual(principals_with_local_roles(root), [])
self.assertEqual(principals_with_local_roles(child), [])
self.assertEqual(map_principals_with_local_roles(root), [])
self.assertEqual(map_principals_with_local_roles(child), [])
set_groups('group:bobsgroup', child, ['role:editor'])
set_groups('bob', root, ['group:bobsgroup'])
set_groups('group:franksgroup', root, ['role:editor'])
self.assertEqual(
set(principals_with_local_roles(child)),
set(['bob', 'group:bobsgroup', 'group:franksgroup'])
)
self.assertEqual(
set(principals_with_local_roles(child, inherit=False)),
set(['group:bobsgroup'])
)
self.assertEqual(
set(principals_with_local_roles(root)),
set(['bob', 'group:franksgroup'])
)
def test_copy_local_groups(self):
self.test_principals_with_local_roles()
root = get_root()
child = root[u'child']
self.assertEqual(
set(principals_with_local_roles(child)),
set(['bob', 'group:bobsgroup', 'group:franksgroup'])
)
# We make a copy of 'child', and we expect the local roles to
# be copied over:
child2 = root['child2'] = child.copy()
DBSession.flush()
self.assertEqual(
set(principals_with_local_roles(child2)),
set(['bob', 'group:bobsgroup', 'group:franksgroup'])
)
self.assertEqual(len(principals_with_local_roles(child)), 3)
# When we now change the local roles of 'child', the copy is
# unaffected:
set_groups('group:bobsgroup', child, [])