本文整理汇总了Python中tests.factories.NodeFactory类的典型用法代码示例。如果您正苦于以下问题:Python NodeFactory类的具体用法?Python NodeFactory怎么用?Python NodeFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestNodeInstitutionDetail
class TestNodeInstitutionDetail(ApiTestCase):
def setUp(self):
super(TestNodeInstitutionDetail, self).setUp()
self.institution = InstitutionFactory()
self.node = NodeFactory(is_public=True)
self.node.primary_institution = self.institution
self.node.save()
self.user = AuthUserFactory()
self.node2 = NodeFactory(creator=self.user)
def test_return_institution(self):
url = '/{0}nodes/{1}/institution/'.format(API_BASE, self.node._id)
res = self.app.get(url)
assert_equal(res.status_code, 200)
assert_equal(res.json['data']['attributes']['name'], self.institution.name)
assert_equal(res.json['data']['id'], self.institution._id)
def test_return_no_institution(self):
url = '/{0}nodes/{1}/institution/'.format(API_BASE, self.node2._id)
res = self.app.get(
url, auth=self.user.auth,
expect_errors=True
)
assert_equal(res.status_code, 404)
示例2: test__initiate_embargo_adds_admins_on_child_nodes
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)
示例3: test_get_most_in_common_contributors
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)
示例4: TestResolveGuid
class TestResolveGuid(OsfTestCase):
def setUp(self):
super(TestResolveGuid, self).setUp()
self.node = NodeFactory()
def test_resolve_guid(self):
res_guid = self.app.get(self.node.web_url_for('node_setting', _guid=True), auth=self.node.creator.auth)
res_full = self.app.get(self.node.web_url_for('node_setting'), auth=self.node.creator.auth)
assert_equal(res_guid.text, res_full.text)
def test_resolve_guid_no_referent(self):
guid = models.Guid.load(self.node._id)
guid.referent = None
guid.save()
res = self.app.get(
self.node.web_url_for('node_setting', _guid=True),
auth=self.node.creator.auth,
expect_errors=True,
)
assert_equal(res.status_code, 404)
@mock.patch('website.project.model.Node.deep_url', None)
def test_resolve_guid_no_url(self):
res = self.app.get(
self.node.web_url_for('node_setting', _guid=True),
auth=self.node.creator.auth,
expect_errors=True,
)
assert_equal(res.status_code, 404)
示例5: test_collect_components_deleted
def test_collect_components_deleted(self):
node = NodeFactory(creator=self.project.creator, parent=self.project)
node.is_deleted = True
collector = rubeus.NodeFileCollector(
self.project, Auth(user=UserFactory())
)
nodes = collector._collect_components(self.project, visited=[])
assert_equal(len(nodes), 0)
示例6: test_migrate_osffiles
def test_migrate_osffiles(self):
node = NodeFactory()
osf_addon = node.get_addon('osffiles')
AddonFilesNodeSettings.remove_one(osf_addon)
assert_false(node.has_addon('osffiles'))
was_migrated = migrate_addons(node)
assert_true(was_migrated)
assert_true(node.has_addon('osffiles'))
示例7: test_migrate_wiki
def test_migrate_wiki(self):
node = NodeFactory()
wiki_addon = node.get_addon('wiki')
AddonWikiNodeSettings.remove_one(wiki_addon)
assert_false(node.has_addon('wiki'))
was_migrated = migrate_addons(node)
assert_true(was_migrated)
assert_true(node.has_addon('wiki'))
示例8: test_serialize_node_search_returns_only_visible_contributors
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'])
示例9: TestValidProject
class TestValidProject(OsfTestCase):
def setUp(self):
super(TestValidProject, self).setUp()
self.project = ProjectFactory()
self.node = NodeFactory(project=self.project)
self.retraction = RetractionFactory()
self.auth = Auth(user=self.project.creator)
def test_populates_kwargs_node(self):
res = valid_project_helper(pid=self.project._id)
assert_equal(res['node'], self.project)
assert_is_none(res['parent'])
def test_populates_kwargs_node_and_parent(self):
res = valid_project_helper(pid=self.project._id, nid=self.node._id)
assert_equal(res['parent'], self.project)
assert_equal(res['node'], self.node)
def test_project_not_found(self):
with assert_raises(HTTPError) as exc_info:
valid_project_helper(pid='fakepid')
assert_equal(exc_info.exception.code, 404)
def test_project_deleted(self):
self.project.is_deleted = True
self.project.save()
with assert_raises(HTTPError) as exc_info:
valid_project_helper(pid=self.project._id)
assert_equal(exc_info.exception.code, 410)
def test_node_not_found(self):
with assert_raises(HTTPError) as exc_info:
valid_project_helper(pid=self.project._id, nid='fakenid')
assert_equal(exc_info.exception.code, 404)
def test_node_deleted(self):
self.node.is_deleted = True
self.node.save()
with assert_raises(HTTPError) as exc_info:
valid_project_helper(pid=self.project._id, nid=self.node._id)
assert_equal(exc_info.exception.code, 410)
def test_valid_project_as_factory_allow_retractions_is_retracted(self):
self.project.is_registration = True
self.project.retraction = self.retraction
self.retraction.state = Sanction.UNAPPROVED
self.retraction.save()
res = as_factory_allow_retractions(pid=self.project._id)
assert_equal(res['node'], self.project)
def test_collection_guid_not_found(self):
collection = CollectionFactory()
collection.add_pointer(self.project, self.auth)
with assert_raises(HTTPError) as exc_info:
valid_project_helper(pid=collection._id, nid=collection._id)
assert_equal(exc_info.exception.code, 404)
示例10: test_fork_serialization
def test_fork_serialization(self):
node = NodeFactory(creator=self.user)
fork = node.fork_node(auth=Auth(user=node.creator))
result = NodeSerializer(fork, context={"request": make_drf_request()}).data
data = result["data"]
# Relationships
relationships = data["relationships"]
forked_from = relationships["forked_from"]["links"]["related"]["href"]
assert_equal(urlparse(forked_from).path, "/{}nodes/{}/".format(API_BASE, node._id))
示例11: test_user_is_admin
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)
示例12: test_serialize_deleted
def test_serialize_deleted(self):
node = NodeFactory()
info = serialize_node(node)
assert_false(info['deleted'])
node.is_deleted = True
info = serialize_node(node)
assert_true(info['deleted'])
node.is_deleted = False
info = serialize_node(node)
assert_false(info['deleted'])
示例13: test_get_contributors_from_parent
def test_get_contributors_from_parent(self):
self.project.add_contributor(AuthUserFactory(), auth=self.auth, visible=True)
self.project.add_contributor(AuthUserFactory(), auth=self.auth, visible=False)
self.project.save()
component = NodeFactory(parent=self.project, creator=self.user)
url = component.api_url_for("get_contributors_from_parent")
res = self.app.get(url, auth=self.user.auth)
# Should be one contributor to the parent who is both visible and
# not a contributor on the component
assert_equal(len(res.json["contributors"]), 1)
示例14: test_a_public_component_from_home_page
def test_a_public_component_from_home_page(self):
component = NodeFactory(title='Foobar Component', is_public=True)
# Searches a part of the name
res = self.app.get('/').maybe_follow()
component.reload()
form = res.forms['searchBar']
form['q'] = 'Foobar'
res = form.submit().maybe_follow()
# A link to the component is shown as a result
assert_in('Foobar Component', res)
示例15: test_collect_js_unique
def test_collect_js_unique(self):
self.project.get_addons.return_value[0].config.include_js = {'files': ['foo.js']}
node = NodeFactory(project=self.project)
mock_node_addon = mock.Mock()
mock_node_addon.config.include_js = {'files': ['foo.js', 'baz.js']}
node.get_addons = mock.Mock()
node.get_addons.return_value = [mock_node_addon]
assert_equal(
rubeus.collect_addon_js(self.project),
{'foo.js', 'baz.js'}
)