本文整理汇总了Python中tests.factories.NodeFactory.add_contributor方法的典型用法代码示例。如果您正苦于以下问题:Python NodeFactory.add_contributor方法的具体用法?Python NodeFactory.add_contributor怎么用?Python NodeFactory.add_contributor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.NodeFactory
的用法示例。
在下文中一共展示了NodeFactory.add_contributor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test__initiate_embargo_adds_admins_on_child_nodes
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test__initiate_embargo_adds_admins_on_child_nodes(self):
project_admin = UserFactory()
project_non_admin = UserFactory()
child_admin = UserFactory()
child_non_admin = UserFactory()
grandchild_admin = UserFactory()
project = ProjectFactory(creator=project_admin)
project.add_contributor(project_non_admin, auth=Auth(project.creator), save=True)
child = NodeFactory(creator=child_admin, parent=project)
child.add_contributor(child_non_admin, auth=Auth(project.creator), save=True)
grandchild = NodeFactory(creator=grandchild_admin, parent=child) # noqa
embargo = project._initiate_embargo(
project.creator,
self.valid_embargo_end_date,
for_existing_registration=True
)
assert_in(project_admin._id, embargo.approval_state)
assert_in(child_admin._id, embargo.approval_state)
assert_in(grandchild_admin._id, embargo.approval_state)
assert_not_in(project_non_admin._id, embargo.approval_state)
assert_not_in(child_non_admin._id, embargo.approval_state)
示例2: test_get_most_in_common_contributors
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_get_most_in_common_contributors(self):
# project 1 (contrib 1, contrib 2, unreg_contrib 3)
# - component 1 (contrib 1)
# project 2 - add should show contrib 1 first (2 links), contrib 2 second (1 link)
contributor_1 = AuthUserFactory()
contributor_2 = AuthUserFactory()
self.project.add_contributor(contributor_1, auth=self.auth)
self.project.add_contributor(contributor_2, auth=self.auth)
# has one unregistered contributor
self.project.add_unregistered_contributor(
fullname=fake.name(),
email=fake.email(),
auth=self.auth,
)
self.project.save()
component = NodeFactory(parent=self.project, creator=self.user)
component.add_contributor(contributor_1, auth=self.auth)
component.save()
project_2 = ProjectFactory(creator=self.user)
project_2.add_contributor(contributor_1, auth=self.auth)
url = project_2.api_url_for('get_most_in_common_contributors')
res = self.app.get(url, auth=self.user.auth)
project_2.reload()
res_contribs = res.json['contributors']
assert_equal(len(res.json['contributors']), 2)
assert_equal(contributor_1._id, res_contribs[0]['id'])
assert_equal(res_contribs[0]['n_projects_in_common'], 2)
assert_equal(contributor_2._id, res_contribs[1]['id'])
assert_equal(res_contribs[1]['n_projects_in_common'], 1)
示例3: test_serialize_node_search_returns_only_visible_contributors
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_serialize_node_search_returns_only_visible_contributors(self):
node = NodeFactory()
non_visible_contributor = UserFactory()
node.add_contributor(non_visible_contributor, visible=False)
serialized_node = _serialize_node_search(node)
assert_equal(serialized_node['firstAuthor'], node.visible_contributors[0].family_name)
assert_equal(len(node.visible_contributors), 1)
assert_false(serialized_node['etal'])
示例4: test_was_not_invited
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_was_not_invited(self):
referrer = UserFactory()
node = NodeFactory(creator=referrer)
user = UserFactory()
node.add_contributor(user, auth=Auth(referrer))
assert_false(is_invited(user))
user.is_invited = None
user.save()
main(dry_run=False)
user.reload()
assert_false(user.is_invited)
示例5: TestComponents
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
class TestComponents(OsfTestCase):
def setUp(self):
super(TestComponents, self).setUp()
self.user = AuthUserFactory()
self.consolidate_auth = Auth(user=self.user)
self.project = ProjectFactory(creator=self.user)
self.project.add_contributor(contributor=self.user, auth=self.consolidate_auth)
# A non-project componenet
self.component = NodeFactory(category="hypothesis", creator=self.user, parent=self.project)
self.component.save()
self.component.set_privacy("public", self.consolidate_auth)
self.component.set_privacy("private", self.consolidate_auth)
self.project.save()
self.project_url = self.project.web_url_for("view_project")
def test_can_create_component_from_a_project(self):
res = self.app.get(self.project.url, auth=self.user.auth).maybe_follow()
assert_in("Add Component", res)
def test_can_create_component_from_a_component(self):
res = self.app.get(self.component.url, auth=self.user.auth).maybe_follow()
assert_in("Add Component", res)
def test_sees_parent(self):
res = self.app.get(self.component.url, auth=self.user.auth).maybe_follow()
parent_title = res.html.find_all("h2", class_="node-parent-title")
assert_equal(len(parent_title), 1)
assert_in(self.project.title, parent_title[0].text) # Bs4 will handle unescaping HTML here
def test_delete_project(self):
res = self.app.get(self.component.url + "settings/", auth=self.user.auth).maybe_follow()
assert_in("Delete {0}".format(self.component.project_or_component), res)
def test_cant_delete_project_if_not_admin(self):
non_admin = AuthUserFactory()
self.component.add_contributor(non_admin, permissions=["read", "write"], auth=self.consolidate_auth, save=True)
res = self.app.get(self.component.url + "settings/", auth=non_admin.auth).maybe_follow()
assert_not_in("Delete {0}".format(self.component.project_or_component), res)
def test_can_configure_comments_if_admin(self):
res = self.app.get(self.component.url + "settings/", auth=self.user.auth).maybe_follow()
assert_in("Configure Commenting", res)
def test_cant_configure_comments_if_not_admin(self):
non_admin = AuthUserFactory()
self.component.add_contributor(non_admin, permissions=["read", "write"], auth=self.consolidate_auth, save=True)
res = self.app.get(self.component.url + "settings/", auth=non_admin.auth).maybe_follow()
assert_not_in("Configure commenting", res)
def test_components_should_have_component_list(self):
res = self.app.get(self.component.url, auth=self.user.auth)
assert_in("Components", res)
示例6: test_user_is_not_admin
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_user_is_not_admin(self):
user = AuthUserFactory()
node = NodeFactory(creator=user)
node.add_contributor(self.user, auth=Auth(user))
res = self.app.post_json_api(
self.institution_nodes_url,
self.create_payload(node._id),
expect_errors=True,
auth=self.user.auth
)
assert_equal(res.status_code, 403)
node.reload()
assert_not_in(self.institution, node.affiliated_institutions)
示例7: test_user_is_read_write
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_user_is_read_write(self):
user = AuthUserFactory()
user.affiliated_institutions.append(self.institution)
node = NodeFactory()
node.add_contributor(user)
node.save()
res = self.app.post_json_api(
self.institution_nodes_url,
self.create_payload(node._id),
auth=user.auth
)
assert_equal(res.status_code, 201)
node.reload()
assert_in(self.institution, node.affiliated_institutions)
示例8: TestInstitutionNodeList
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
class TestInstitutionNodeList(ApiTestCase):
def setUp(self):
super(TestInstitutionNodeList, self).setUp()
self.institution = InstitutionFactory()
self.node1 = NodeFactory(is_public=True)
self.node1.primary_institution = self.institution
self.node1.save()
self.user1 = AuthUserFactory()
self.user2 = AuthUserFactory()
self.node2 = NodeFactory(creator=self.user1, is_public=False)
self.node2.primary_institution = self.institution
self.node2.add_contributor(self.user2, auth=Auth(self.user1))
self.node2.save()
self.node3 = NodeFactory(creator=self.user2, is_public=False)
self.node3.primary_institution = self.institution
self.node3.save()
self.institution_node_url = '/{0}institutions/{1}/nodes/'.format(API_BASE, self.institution._id)
def test_return_all_public_nodes(self):
res = self.app.get(self.institution_node_url)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.node1._id, ids)
assert_not_in(self.node2._id, ids)
assert_not_in(self.node3._id, ids)
def test_return_private_nodes_with_auth(self):
res = self.app.get(self.institution_node_url, auth=self.user1.auth)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.node1._id, ids)
assert_in(self.node2._id, ids)
assert_not_in(self.node3._id, ids)
def test_return_private_nodes_mixed_auth(self):
res = self.app.get(self.institution_node_url, auth=self.user2.auth)
assert_equal(res.status_code, 200)
ids = [each['id'] for each in res.json['data']]
assert_in(self.node1._id, ids)
assert_in(self.node2._id, ids)
assert_in(self.node3._id, ids)
示例9: test_remove_institution_not_admin
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_remove_institution_not_admin(self):
node = NodeFactory(creator=self.user)
user = AuthUserFactory()
node.primary_institution = self.institution
node.add_contributor(user, auth=Auth(self.user))
node.save()
res = self.app.put_json_api(
'/{0}nodes/{1}/relationships/institution/'.format(API_BASE, node._id),
{'data': None},
auth=user.auth,
expect_errors=True
)
assert_equal(res.status_code, 403)
assert_equal(node.primary_institution, self.institution)
示例10: test_user_is_read_only
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_user_is_read_only(self):
user = AuthUserFactory()
user.affiliated_institutions.append(self.institution)
node = NodeFactory()
node.add_contributor(user, permissions=[permissions.READ])
node.save()
res = self.app.post_json_api(
self.institution_nodes_url,
self.create_payload(node._id),
auth=user.auth,
expect_errors=True
)
assert_equal(res.status_code, 403)
node.reload()
assert_not_in(self.institution, node.affiliated_institutions)
示例11: test_do_migration
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_do_migration(self):
project = ProjectFactory()
user = UserFactory()
node = NodeFactory(parent=project)
node.add_contributor(contributor=user)
node.save()
for log in node.logs:
if log.action == 'contributor_added':
project.logs.append(log)
project.save()
node_list = get_targets()
do_migration(node_list)
logs = [each for each in project.logs if each.action == 'contributor_added']
assert len(logs) is 1
assert logs[0].should_hide is True
示例12: test_migrate_node
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_migrate_node(self):
external_admin = UserFactory()
personal_admin = UserFactory()
staff_user = UserFactory()
personal_accounts = [personal_admin.username]
conference = ConferenceFactory(admins=[external_admin, personal_admin])
node = NodeFactory()
node.add_contributor(staff_user)
node.add_contributor(external_admin)
node.add_contributor(personal_admin)
migrate_node(node, conference, staff_user, personal_accounts, dry_run=False)
node.reload()
assert_in(staff_user, node.contributors)
assert_in(external_admin, node.contributors)
assert_not_in(personal_admin, node.contributors)
# Verify that migration is idempotent
migrate_node(node, conference, staff_user, personal_accounts, dry_run=False)
node.reload()
assert_in(staff_user, node.contributors)
assert_in(external_admin, node.contributors)
assert_not_in(personal_admin, node.contributors)
示例13: test_get_children_only_returns_child_nodes_with_admin_permissions
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test_get_children_only_returns_child_nodes_with_admin_permissions(self):
user = UserFactory()
admin_project = ProjectFactory()
admin_project.add_contributor(
user, auth=Auth(admin_project.creator), permissions=permissions.expand_permissions(permissions.ADMIN)
)
admin_project.save()
admin_component = NodeFactory(parent=admin_project)
admin_component.add_contributor(
user, auth=Auth(admin_component.creator), permissions=permissions.expand_permissions(permissions.ADMIN)
)
admin_component.save()
read_and_write = NodeFactory(parent=admin_project)
read_and_write.add_contributor(
user, auth=Auth(read_and_write.creator), permissions=permissions.expand_permissions(permissions.WRITE)
)
read_and_write.save()
read_only = NodeFactory(parent=admin_project)
read_only.add_contributor(
user, auth=Auth(read_only.creator), permissions=permissions.expand_permissions(permissions.READ)
)
read_only.save()
non_contributor = NodeFactory(parent=admin_project)
components = _get_children(admin_project, Auth(user))
assert_equal(len(components), 1)
示例14: test__initiate_retraction_adds_admins_on_child_nodes
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
def test__initiate_retraction_adds_admins_on_child_nodes(self):
project_admin = UserFactory()
project_non_admin = UserFactory()
child_admin = UserFactory()
child_non_admin = UserFactory()
grandchild_admin = UserFactory()
project = ProjectFactory(creator=project_admin)
project.add_contributor(project_non_admin, auth=Auth(project.creator), save=True)
child = NodeFactory(creator=child_admin, parent=project)
child.add_contributor(child_non_admin, auth=Auth(child.creator), save=True)
grandchild = NodeFactory(creator=grandchild_admin, parent=child) # noqa
registration = RegistrationFactory(project=project)
retraction = registration._initiate_retraction(registration.creator)
assert_in(project_admin._id, retraction.approval_state)
assert_in(child_admin._id, retraction.approval_state)
assert_in(grandchild_admin._id, retraction.approval_state)
assert_not_in(project_non_admin._id, retraction.approval_state)
assert_not_in(child_non_admin._id, retraction.approval_state)
示例15: TestInstitutionRelationshipNodes
# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_contributor [as 别名]
#.........这里部分代码省略.........
assert_in(node._id, node_ids)
node.reload()
assert_in(self.institution, node.affiliated_institutions)
def test_user_does_not_have_node(self):
node = NodeFactory()
res = self.app.post_json_api(
self.institution_nodes_url,
self.create_payload(node._id),
expect_errors=True,
auth=self.user.auth
)
assert_equal(res.status_code, 403)
node.reload()
assert_not_in(self.institution, node.affiliated_institutions)
def test_user_is_admin(self):
node = NodeFactory(creator=self.user)
res = self.app.post_json_api(
self.institution_nodes_url,
self.create_payload(node._id),
auth=self.user.auth
)
assert_equal(res.status_code, 201)
node.reload()
assert_in(self.institution, node.affiliated_institutions)
def test_user_is_read_write(self):
user = AuthUserFactory()
user.affiliated_institutions.append(self.institution)
node = NodeFactory()
node.add_contributor(user)
node.save()
res = self.app.post_json_api(
self.institution_nodes_url,
self.create_payload(node._id),
auth=user.auth
)
assert_equal(res.status_code, 201)
node.reload()
assert_in(self.institution, node.affiliated_institutions)
def test_user_is_read_only(self):
user = AuthUserFactory()
user.affiliated_institutions.append(self.institution)
node = NodeFactory()
node.add_contributor(user, permissions=[permissions.READ])
node.save()
res = self.app.post_json_api(
self.institution_nodes_url,
self.create_payload(node._id),
auth=user.auth,
expect_errors=True
)
assert_equal(res.status_code, 403)
node.reload()
assert_not_in(self.institution, node.affiliated_institutions)
def test_user_is_admin_but_not_affiliated(self):
user = AuthUserFactory()
node = NodeFactory(creator=user)