Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_some_groups():
session = DBSession()
root = get_root()
child = root[u'child'] = Node()
grandchild = child[u'grandchild'] = Node()
session.flush()
# root:
# bob -> group:bobsgroup
# frank -> group:franksgroup
# group:franksgroup -> role:editor
# child:
# group:bobsgroup -> group:franksgroup
# grandchild:
# group:franksgroup -> role:admin
# group:franksgroup -> group:bobsgroup
# bob and frank are a site-wide members of their respective groups:
set_groups('bob', root, ['group:bobsgroup'])
def test_search(self):
from kotti.views.users import users_manage
root = get_root()
request = DummyRequest()
P = get_principals()
TestNodeShare.add_some_principals()
request.params['search'] = u''
request.params['query'] = u'Joe'
entries = users_manage(root, request)['entries']
self.assertEqual(len(entries), 0)
self.assertEqual(request.session.pop_flash('notice'),
[u'No users or groups found.'])
request.params['query'] = u'Bob'
entries = users_manage(root, request)['entries']
self.assertEqual(entries[0][0], P['bob'])
self.assertEqual(entries[0][1], ([], []))
self.assertEqual(entries[1][0], P['group:bobsgroup'])
self.assertEqual(entries[1][1], ([], []))
def test_apply(self):
from kotti.views.users import share_node
root = get_root()
request = DummyRequest()
self.add_some_principals()
request.params['apply'] = u''
share_node(root, request)
self.assertEqual(request.session.pop_flash('notice'),
[u'No changes made.'])
self.assertEqual(list_groups('bob', root), [])
set_groups('bob', root, ['role:special'])
request.params['role::bob::role:owner'] = u'1'
request.params['role::bob::role:editor'] = u'1'
request.params['orig-role::bob::role:owner'] = u''
request.params['orig-role::bob::role:editor'] = u''
share_node(root, request)
def test_unique_constraint(self):
# Try to add two children with the same name to the root node:
session = DBSession()
root = get_root()
session.add(Node(name=u'child1', parent=root))
session.add(Node(name=u'child1', parent=root))
self.assertRaises(IntegrityError, session.flush)
def test_simple(self):
root = get_root()
set_groups('bob', root, ['role:editor'])
self.assertEqual(
list_groups('bob', root), ['role:editor'])
self.assertEqual(
list_groups_raw(u'bob', root), set(['role:editor']))
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)
def test_multiple_types(self):
from kotti.views.util import addable_types
# Test a scenario where we may add multiple types to a folder:
root = get_root()
request = DummyRequest()
with contents_addable():
# We should be able to add both Nodes and Documents now:
possible_parents, possible_types = addable_types(root, request)
self.assertEqual(len(possible_parents), 1)
self.assertEqual(possible_parents[0]['factories'],
[Document, Content])
document_info, node_info = possible_types
self.assertEqual(document_info['factory'], Document)
self.assertEqual(node_info['factory'], Content)
self.assertEqual(document_info['nodes'], [root])
self.assertEqual(node_info['nodes'], [root])
def test_container_methods(self):
session = DBSession()
# Test some of Node's container methods:
root = get_root()
self.assertEquals(root.keys(), [])
child1 = Node(name=u'child1', parent=root)
session.add(child1)
self.assertEquals(root.keys(), [u'child1'])
self.assertEquals(root[u'child1'], child1)
del root[u'child1']
self.assertEquals(root.keys(), [])
# When we delete a parent node, all its child nodes will be
# released as well:
root[u'child2'] = Node()
root[u'child2'][u'subchild'] = Node()
self.assertEquals(
session.query(Node).filter(Node.name == u'subchild').count(), 1)
for module in settings["kotti.base_includes"]:
config.include(module)
config.commit()
# Modules in 'pyramid.includes' and 'kotti.zcml_includes' may
# override 'kotti.base_includes':
if pyramid_includes:
for module in pyramid_includes.split():
config.include(module)
for name in settings["kotti.zcml_includes"].strip().split():
config.load_zcml(name)
config.commit()
config._set_root_factory(get_root)
return config
def cancel_success(self, appstruct):
location = self.request.resource_url(get_root())
return HTTPFound(location=location)