本文整理汇总了Python中tests.factories.ProjectFactory.manage_contributors方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory.manage_contributors方法的具体用法?Python ProjectFactory.manage_contributors怎么用?Python ProjectFactory.manage_contributors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.ProjectFactory
的用法示例。
在下文中一共展示了ProjectFactory.manage_contributors方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestWikiShareJSMongo
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import manage_contributors [as 别名]
class TestWikiShareJSMongo(OsfTestCase):
@classmethod
def setUpClass(cls):
super(TestWikiShareJSMongo, cls).setUpClass()
cls._original_sharejs_db_name = settings.SHAREJS_DB_NAME
settings.SHAREJS_DB_NAME = 'sharejs_test'
def setUp(self):
super(TestWikiShareJSMongo, self).setUp()
self.user = AuthUserFactory()
self.project = ProjectFactory(is_public=True, creator=self.user)
self.wname = 'foo.bar'
self.wkey = to_mongo_key(self.wname)
self.private_uuid = generate_private_uuid(self.project, self.wname)
self.sharejs_uuid = get_sharejs_uuid(self.project, self.wname)
# Create wiki page
self.project.update_node_wiki(self.wname, 'Hello world', Auth(self.user))
self.wiki_page = self.project.get_wiki_page(self.wname)
# Insert mongo data for current project/wiki
self.db = share_db()
example_uuid = EXAMPLE_DOCS[0]['_id']
self.example_docs = deepcopy(EXAMPLE_DOCS)
self.example_docs[0]['_id'] = self.sharejs_uuid
self.db.docs.insert(self.example_docs)
self.example_ops = deepcopy(EXAMPLE_OPS)
for item in self.example_ops:
item['_id'] = item['_id'].replace(example_uuid, self.sharejs_uuid)
item['name'] = item['name'].replace(example_uuid, self.sharejs_uuid)
self.db.docs_ops.insert(self.example_ops)
@mock.patch('website.addons.wiki.utils.broadcast_to_sharejs')
def test_migrate_uuid(self, mock_sharejs):
migrate_uuid(self.project, self.wname)
assert_is_none(self.db.docs.find_one({'_id': self.sharejs_uuid}))
assert_is_none(self.db.docs_ops.find_one({'name': self.sharejs_uuid}))
new_sharejs_uuid = get_sharejs_uuid(self.project, self.wname)
assert_equal(
EXAMPLE_DOCS[0]['_data'],
self.db.docs.find_one({'_id': new_sharejs_uuid})['_data']
)
assert_equal(
len([item for item in self.example_ops if item['name'] == self.sharejs_uuid]),
len([item for item in self.db.docs_ops.find({'name': new_sharejs_uuid})])
)
@mock.patch('website.addons.wiki.utils.broadcast_to_sharejs')
def test_migrate_uuid_no_mongo(self, mock_sharejs):
# Case where no edits have been made to the wiki
wname = 'bar.baz'
wkey = to_mongo_key(wname)
share_uuid = generate_private_uuid(self.project, wname)
sharejs_uuid = get_sharejs_uuid(self.project, wname)
self.project.update_node_wiki(wname, 'Hello world', Auth(self.user))
wiki_page = self.project.get_wiki_page(wname)
migrate_uuid(self.project, wname)
assert_not_equal(share_uuid, self.project.wiki_private_uuids.get(wkey))
assert_is_none(self.db.docs.find_one({'_id': sharejs_uuid}))
assert_is_none(self.db.docs_ops.find_one({'name': sharejs_uuid}))
@mock.patch('website.addons.wiki.utils.broadcast_to_sharejs')
def test_migrate_uuid_updates_node(self, mock_sharejs):
migrate_uuid(self.project, self.wname)
assert_not_equal(self.private_uuid, self.project.wiki_private_uuids[self.wkey])
@mock.patch('website.addons.wiki.utils.broadcast_to_sharejs')
def test_manage_contributors_updates_uuid(self, mock_sharejs):
user = UserFactory()
self.project.add_contributor(
contributor=user,
permissions=['read', 'write', 'admin'],
auth=Auth(user=self.user),
)
self.project.save()
assert_equal(self.private_uuid, self.project.wiki_private_uuids[self.wkey])
# Removing admin permission does nothing
self.project.manage_contributors(
user_dicts=[
{'id': user._id, 'permission': 'write', 'visible': True},
{'id': self.user._id, 'permission': 'admin', 'visible': True},
],
auth=Auth(user=self.user),
save=True,
)
assert_equal(self.private_uuid, self.project.wiki_private_uuids[self.wkey])
# Removing write permission migrates uuid
self.project.manage_contributors(
user_dicts=[
{'id': user._id, 'permission': 'read', 'visible': True},
{'id': self.user._id, 'permission': 'admin', 'visible': True},
],
auth=Auth(user=self.user),
save=True,
)
assert_not_equal(self.private_uuid, self.project.wiki_private_uuids[self.wkey])
#.........这里部分代码省略.........