当前位置: 首页>>代码示例>>Python>>正文


Python NodeFactory.save方法代码示例

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


在下文中一共展示了NodeFactory.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestNodeInstitutionDetail

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
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,代码行数:28,代码来源:test_node_institutions_detail.py

示例2: test_get_most_in_common_contributors

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [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)
开发者ID:GageGaskins,项目名称:osf.io,代码行数:31,代码来源:test_contributors_views.py

示例3: TestShortUrls

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
class TestShortUrls(OsfTestCase):
    def setUp(self):
        super(TestShortUrls, self).setUp()
        self.user = AuthUserFactory()
        self.auth = self.user.auth
        self.consolidate_auth = Auth(user=self.user)
        self.project = ProjectFactory(creator=self.user)
        # A non-project componenet
        self.component = NodeFactory(category="hypothesis", creator=self.user)
        self.project.nodes.append(self.component)
        self.component.save()
        # Hack: Add some logs to component; should be unnecessary pending
        # improvements to factories from @rliebz
        self.component.set_privacy("public", auth=self.consolidate_auth)
        self.component.set_privacy("private", auth=self.consolidate_auth)
        self.wiki = NodeWikiFactory(user=self.user, node=self.component)

    def _url_to_body(self, url):
        return self.app.get(url, auth=self.auth).maybe_follow(auth=self.auth).normal_body

    def test_project_url(self):
        assert_equal(self._url_to_body(self.project.deep_url), self._url_to_body(self.project.url))

    def test_component_url(self):
        assert_equal(self._url_to_body(self.component.deep_url), self._url_to_body(self.component.url))

    def test_wiki_url(self):
        assert_equal(self._url_to_body(self.wiki.deep_url), self._url_to_body(self.wiki.url))
开发者ID:Alpani,项目名称:osf.io,代码行数:30,代码来源:webtest_tests.py

示例4: TestValidProject

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
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,代码行数:59,代码来源:test_project_decorators.py

示例5: test_everything_else_is_migrated_to_other

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
    def test_everything_else_is_migrated_to_other(self):
        node1 = NodeFactory(category='background')
        migrate_category(node1)
        node1.save()
        assert node1.category == 'other'

        node2 = NodeFactory(category=u'プロジェクト')
        migrate_category(node2)
        node2.save()
        assert node2.category == 'other'
开发者ID:adlius,项目名称:osf.io,代码行数:12,代码来源:migrate_categories.py

示例6: TestComponents

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [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)
开发者ID:Alpani,项目名称:osf.io,代码行数:54,代码来源:webtest_tests.py

示例7: test_retrieve_private_node_with_auth_with_inst

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
    def test_retrieve_private_node_with_auth_with_inst(self):
        node = NodeFactory(is_public=False, creator=self.user)
        node.primary_institution = self.institution
        node.save()

        res = self.app.get(
            '/{0}nodes/{1}/relationships/institution/'.format(API_BASE, node._id),
            auth=self.user.auth
        )

        assert_equal(res.status_code, 200)
        assert_equal(res.json['data']['type'], 'institutions')
        assert_equal(res.json['data']['id'], self.institution._id)
开发者ID:545zhou,项目名称:osf.io,代码行数:15,代码来源:test_node_relationship_institution.py

示例8: test_only_add_existent_with_permissions

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
    def test_only_add_existent_with_permissions(self):
        node = NodeFactory(creator=self.user)
        node.affiliated_institutions.append(self.institution)
        node.save()
        assert_in(self.institution, self.node1.affiliated_institutions)
        assert_in(self.institution, node.affiliated_institutions)

        res = self.app.post_json_api(
            self.institution_nodes_url,
            self.create_payload(node._id, self.node1._id),
            auth=self.user.auth
        )

        assert_equal(res.status_code, 204)
开发者ID:brianjgeiger,项目名称:osf.io,代码行数:16,代码来源:test_institution_relationship_nodes.py

示例9: test_valid_categories_not_migrated

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
    def test_valid_categories_not_migrated(self):
        node1 = NodeFactory(category='project')
        node2 = NodeFactory(category='hypothesis')

        was_migrated1 = migrate_category(node1)
        was_migrated2 = migrate_category(node2)

        node1.save()
        node2.save()

        assert was_migrated1 is False
        assert was_migrated2 is False
        assert node1.category == 'project'
        assert node2.category == 'hypothesis'
开发者ID:adlius,项目名称:osf.io,代码行数:16,代码来源:migrate_categories.py

示例10: test_remove_institution_admin

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
    def test_remove_institution_admin(self):
        node = NodeFactory(creator=self.user)
        node.primary_institution = self.institution
        node.save()

        res = self.app.put_json_api(
            '/{0}nodes/{1}/relationships/institution/'.format(API_BASE, node._id),
            {'data': None},
            auth=self.user.auth
        )

        assert_equal(res.status_code, 204)
        node.reload()
        assert_equal(node.primary_institution, None)
开发者ID:545zhou,项目名称:osf.io,代码行数:16,代码来源:test_node_relationship_institution.py

示例11: test_user_is_read_write

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [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)
开发者ID:alexschiller,项目名称:osf.io,代码行数:17,代码来源:test_institution_relationship_nodes.py

示例12: test_serialize_log

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
    def test_serialize_log(self):
        node = NodeFactory(category="hypothesis")
        node.save()
        log = NodeLogFactory(params={"node": node._id}, node=node, original_node=node)
        d = serialize_log(log)
        assert_equal(d["action"], log.action)
        assert_equal(d["node"]["node_type"], "component")
        assert_equal(d["node"]["category"], "Hypothesis")

        assert_equal(d["node"]["url"], log.node.url)
        assert_equal(d["date"], framework_utils.iso8601format(log.date))
        assert_in("contributors", d)
        assert_equal(d["user"]["fullname"], log.user.fullname)
        assert_equal(d["user"]["url"], log.user.url)
        assert_equal(d["params"], log.params)
        assert_equal(d["node"]["title"], log.node.title)
开发者ID:kch8qx,项目名称:osf.io,代码行数:18,代码来源:test_serializers.py

示例13: test_delete_user_is_admin_but_not_affiliated_with_inst

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
    def test_delete_user_is_admin_but_not_affiliated_with_inst(self):
        user = AuthUserFactory()
        node = NodeFactory(creator=user)
        node.affiliated_institutions.append(self.institution)
        node.save()
        assert_in(self.institution, node.affiliated_institutions)

        res = self.app.delete_json_api(
            self.institution_nodes_url,
            self.create_payload(node._id),
            auth=user.auth
        )

        assert_equal(res.status_code, 204)
        node.reload()
        assert_not_in(self.institution, node.affiliated_institutions)
开发者ID:brianjgeiger,项目名称:osf.io,代码行数:18,代码来源:test_institution_relationship_nodes.py

示例14: test_delete_user_is_admin_but_not_affiliated_with_inst

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [as 别名]
    def test_delete_user_is_admin_but_not_affiliated_with_inst(self):
        user = AuthUserFactory()
        node = NodeFactory(creator=user)
        node.affiliated_institutions.append(self.institution1)
        node.save()
        assert_in(self.institution1, node.affiliated_institutions)

        res = self.app.delete_json_api(
            '/{0}nodes/{1}/relationships/institutions/'.format(API_BASE, node._id),
            self.create_payload(self.institution1._id),
            auth=user.auth,
        )

        assert_equal(res.status_code, 204)
        node.reload()
        assert_not_in(self.institution1, node.affiliated_institutions)
开发者ID:brianjgeiger,项目名称:osf.io,代码行数:18,代码来源:test_node_relationship_institutions.py

示例15: test_remove_institution_not_admin

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import save [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)
开发者ID:545zhou,项目名称:osf.io,代码行数:18,代码来源:test_node_relationship_institution.py


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