def custom_setup(self): become_trusted(username='******') for item_names, item_acl, item_content in self.items: meta = {NAME: item_names} if item_acl is not None: meta.update({ACL: item_acl}) update_item(item_names[0], meta, item_content)
def custom_setup(self): become_trusted(username='******') for item_name, item_acl, item_content in self.items: if item_acl is not None: update_item(item_name, {ACL: item_acl}, item_content) else: update_item(item_name, {}, item_content)
def test_validjson(): """ Tests for changes to metadata when modifying an item. Does not apply to usersettings form. """ app.cfg.namespace_mapping = [(u'', 'default_backend'), (u'ns1/', 'default_backend'), (u'users/', 'other_backend')] item = Item.create(u'users/existingname') meta = {NAMESPACE: u'users', CONTENTTYPE: u'text/plain;charset=utf-8'} become_trusted() item._save(meta, data='This is a valid Item.') valid_itemid = 'a1924e3d0a34497eab18563299d32178' # ('names', 'namespace', 'field', 'value', 'result') tests = [([u'somename', u'@revid'], '', '', 'somename', False), # item names cannot begin with @ # TODO for above? - create item @x, get error message, change name in meta to xx, get an item with names @40x and alias of xx ([u'bar', u'ns1'], '', '', 'bar', False), # item names cannot match namespace names ([u'foo', u'foo', u'bar'], '', '', 'foo', False), # names in the name list must be unique. ([u'ns1ns2ns3', u'ns1/subitem'], '', '', 'valid', False), # Item names must not match with existing namespaces; items cannot be in 2 namespaces ([u'foobar', u'validname'], '', ITEMID, valid_itemid + '8080', False), # attempts to change itemid in meta result in "Item(s) named foobar, validname already exist." ([u'barfoo', u'validname'], '', ITEMID, valid_itemid.replace('a', 'y'), False), # similar to above ([], '', 'itemid', valid_itemid, True), # deleting all names from the metadata of an existing item will make it nameless, succeeds ([u'existingname'], 'users', '', 'existingname', False), # item already exists ] for name, namespace, field, value, result in tests: meta = {NAME: name, NAMESPACE: namespace} x = JSON(json.dumps(meta)) y = Names(name) state = dict(fqname=CompositeName(namespace, field, value), itemid=None, meta=meta) value = x.validate(state) and y.validate(state) assert value == result
def test_dict(self): become_trusted() somedict = {u"One": u"1", u"Two": u"2"} update_item(u'TestDict', {SOMEDICT: somedict}, "This is a dict item.") return u"TestDict"
def custom_setup(self): become_trusted() somedict = {"First": "first item", "text with spaces": "second item", 'Empty string': '', "Last": "last item"} update_item('SomeTestDict', {SOMEDICT: somedict}, DATA) somedict = {"One": "1", "Two": "2"} update_item('SomeOtherTestDict', {SOMEDICT: somedict}, DATA)
def custom_setup(self): become_trusted() somedict = { u"First": u"first item", u"text with spaces": u"second item", u'Empty string': u'', u"Last": u"last item" } update_item(u'SomeTestDict', {SOMEDICT: somedict}, DATA) somedict = {u"One": u"1", u"Two": u"2"} update_item(u'SomeOtherTestDict', {SOMEDICT: somedict}, DATA)
def test_appending_group_item(self): """ Test scalability by appending a name to a large list of group members. """ become_trusted() # long list of users members = create_random_string_list(length=15, count=1234) test_user = create_random_string_list(length=15, count=1)[0] update_item(u'UserGroup', {USERGROUP: members}, DATA) update_item(u'UserGroup', {USERGROUP: members + [test_user]}, '') result = test_user in flaskg.groups['UserGroup'] assert result
def test_rename_group_item(self): """ Tests renaming of a group item. """ become_trusted() update_item(u'SomeGroup', {USERGROUP: ["ExampleUser"]}, DATA) assert u'ExampleUser' in flaskg.groups[u'SomeGroup'] pytest.raises(GroupDoesNotExistError, lambda: flaskg.groups[u'AnotherGroup']) update_item(u'SomeGroup', { NAME: [ u'AnotherGroup', ], USERGROUP: ["ExampleUser"] }, DATA) assert u'ExampleUser' in flaskg.groups[u'AnotherGroup'] pytest.raises(GroupDoesNotExistError, lambda: flaskg.groups[u'SomeGroup'])
def test_wiki_backend_item_acl_usergroupmember_item(self): """ Test if the wiki group backend works with acl code. First check acl rights of a user that is not a member of group then add user member to an item group and check acl rights """ become_trusted() update_item(u'NewGroup', {USERGROUP: ["ExampleUser"]}, DATA) acl_rights = ["NewGroup:read,write"] acl = AccessControlList(acl_rights, valid=app.cfg.acl_rights_contents) has_rights_before = acl.may(u"AnotherUser", "read") # update item - add AnotherUser to a item group NewGroup update_item(u'NewGroup', {USERGROUP: ["AnotherUser"]}, '') has_rights_after = acl.may(u"AnotherUser", "read") assert not has_rights_before, 'AnotherUser has no read rights because in the beginning he is not a member of a group item NewGroup' assert has_rights_after, 'AnotherUser must have read rights because after appenditem he is member of NewGroup'
def test_member_removed_from_group_item(self): """ Tests appending a member to a large list of group members and recreating the item without the member. """ become_trusted() # long list of users members = create_random_string_list() update_item(u'UserGroup', {USERGROUP: members}, DATA) # updates the text with the text_user test_user = create_random_string_list(length=15, count=1)[0] update_item(u'UserGroup', {USERGROUP: [test_user]}, DATA) result = test_user in flaskg.groups[u'UserGroup'] assert result # updates the text without test_user update_item(u'UserGroup', {}, DATA) result = test_user in flaskg.groups[u'UserGroup'] assert not result
def testCRUD(self): name = u'NewItem' contenttype = u'text/plain;charset=utf-8' data = 'foobar' meta = {'foo': 'bar', CONTENTTYPE: contenttype} comment = u'saved it' become_trusted() item = Item.create(name) # save rev 0 item._save(meta, data, comment=comment) # check save result item = Item.create(name) saved_meta, saved_data = item.meta, item.content.data assert saved_meta[CONTENTTYPE] == contenttype assert saved_meta[COMMENT] == comment assert saved_data == data data = rev1_data = data * 10000 comment += u' again' # save rev 1 item._save(meta, data, comment=comment) # check save result item = Item.create(name) saved_meta, saved_data = dict(item.meta), item.content.data assert saved_meta[CONTENTTYPE] == contenttype assert saved_meta[COMMENT] == comment assert saved_data == data data = '' comment = 'saved empty data' # save rev 2 (auto delete) item._save(meta, data, comment=comment) # check save result item = Item.create(name) saved_meta, saved_data = dict(item.meta), item.content.data assert saved_meta[CONTENTTYPE] == contenttype assert saved_meta[COMMENT] == comment assert saved_data == data
def custom_setup(self): become_trusted() for group, members in self.test_groups.iteritems(): update_item(group, {USERGROUP: members}, DATA)