• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python factories.NodeFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tests.factories.NodeFactory的典型用法代码示例。如果您正苦于以下问题:Python NodeFactory类的具体用法?Python NodeFactory怎么用?Python NodeFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了NodeFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:545zhou,项目名称:osf.io,代码行数:26,代码来源:test_node_institutions_detail.py


示例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)
开发者ID:mchelen,项目名称:osf.io,代码行数:26,代码来源:test_embargoes.py


示例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)
开发者ID:GageGaskins,项目名称:osf.io,代码行数:29,代码来源:test_contributors_views.py


示例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)
开发者ID:545zhou,项目名称:osf.io,代码行数:30,代码来源:test_guids.py


示例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)
开发者ID:cldershem,项目名称:osf.io,代码行数:8,代码来源:test_rubeus.py


示例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'))
开发者ID:adlius,项目名称:osf.io,代码行数:8,代码来源:ensure_wiki_and_files.py


示例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'))
开发者ID:adlius,项目名称:osf.io,代码行数:8,代码来源:ensure_wiki_and_files.py


示例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'])
开发者ID:arpitar,项目名称:osf.io,代码行数:9,代码来源:test_serializers.py


示例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)
开发者ID:DanielSBrown,项目名称:osf.io,代码行数:57,代码来源:test_project_decorators.py


示例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))
开发者ID:Alpani,项目名称:osf.io,代码行数:10,代码来源:test_serializers.py


示例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)
开发者ID:alexschiller,项目名称:osf.io,代码行数:10,代码来源:test_institution_relationship_nodes.py


示例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'])
开发者ID:545zhou,项目名称:osf.io,代码行数:10,代码来源:test_serializers.py


示例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)
开发者ID:njantrania,项目名称:osf.io,代码行数:10,代码来源:test_contributors_views.py


示例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)
开发者ID:baylee-d,项目名称:osf.io,代码行数:10,代码来源:webtest_tests.py


示例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'}
     )
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:11,代码来源:test_rubeus.py


示例16: test_was_not_invited

 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)
开发者ID:545zhou,项目名称:osf.io,代码行数:11,代码来源:test_migrate_was_invited.py


示例17: test_serialize_node_for_logs

    def test_serialize_node_for_logs(self):
        node = NodeFactory()
        d = node.serialize()

        assert_equal(d["id"], node._primary_key)
        assert_equal(d["category"], node.category_display)
        assert_equal(d["node_type"], node.project_or_component)
        assert_equal(d["url"], node.url)
        assert_equal(d["title"], node.title)
        assert_equal(d["api_url"], node.api_url)
        assert_equal(d["is_public"], node.is_public)
        assert_equal(d["is_registration"], node.is_registration)
开发者ID:kch8qx,项目名称:osf.io,代码行数:12,代码来源:test_serializers.py


示例18: test_serialize_wiki_toc

    def test_serialize_wiki_toc(self):
        project = ProjectFactory()
        auth = Auth(project.creator)
        NodeFactory(project=project, creator=project.creator)
        no_wiki = NodeFactory(project=project, creator=project.creator)
        project.save()

        serialized = _serialize_wiki_toc(project, auth=auth)
        assert_equal(len(serialized), 2)
        no_wiki.delete_addon('wiki', auth=auth)
        serialized = _serialize_wiki_toc(project, auth=auth)
        assert_equal(len(serialized), 1)
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:12,代码来源:test_wiki.py


示例19: test_affected_nodes

    def test_affected_nodes(self):
        affected_node = NodeFactory()
        AddonWikiNodeSettings.remove_one(affected_node.get_addon('wiki'))
        assert_false(affected_node.has_addon('wiki'))

        unaffected_node = NodeFactory()
        assert_true(unaffected_node.has_addon('wiki'))

        affected_nodes = list(get_affected_nodes(self.db, AddonWikiNodeSettings))

        assert_in(affected_node, affected_nodes)
        assert_not_in(unaffected_node, affected_nodes)
开发者ID:adlius,项目名称:osf.io,代码行数:12,代码来源:ensure_wiki_and_files.py


示例20: test_collect_js_unique

 def test_collect_js_unique(self):
     self.project.get_addons.return_value[0].config.include_js = {'files': ['foo.js']}
     self.project.get_addons.return_value[0].config.short_name = 'dropbox'
     node = NodeFactory(parent=self.project)
     mock_node_addon = mock.Mock()
     mock_node_addon.config.include_js = {'files': ['foo.js', 'baz.js']}
     mock_node_addon.config.short_name = 'dropbox'
     node.get_addons = mock.Mock()
     node.get_addons.return_value = [mock_node_addon]
     result = rubeus.collect_addon_js(self.project)
     assert_in('foo.js', result)
     assert_in('baz.js', result)
开发者ID:cldershem,项目名称:osf.io,代码行数:12,代码来源:test_rubeus.py



注:本文中的tests.factories.NodeFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python factories.PreprintFactory类代码示例发布时间:2022-05-27
下一篇:
Python factories.CommentFactory类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap