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


Python NodeFactory.add_pointer方法代码示例

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


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

示例1: test_linked_nodes_only_return_viewable_nodes

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_pointer [as 别名]
    def test_linked_nodes_only_return_viewable_nodes(self):
        user = AuthUserFactory()
        new_linking_node = NodeFactory(creator=user)
        self.linked_node.add_contributor(user, auth=self.auth, save=True)
        self.linked_node2.add_contributor(user, auth=self.auth, save=True)
        self.public_node.add_contributor(user, auth=self.auth, save=True)
        new_linking_node.add_pointer(self.linked_node, auth=Auth(user))
        new_linking_node.add_pointer(self.linked_node2, auth=Auth(user))
        new_linking_node.add_pointer(self.public_node, auth=Auth(user))
        new_linking_node.save()
        new_linking_registration = RegistrationFactory(project=new_linking_node, creator=self.user)

        res = self.app.get(
            '/{}registrations/{}/linked_nodes/'.format(API_BASE, new_linking_registration._id),
            auth=user.auth
        )

        assert_equal(res.status_code, 200)
        nodes_returned = [linked_node['id'] for linked_node in res.json['data']]
        assert_equal(len(nodes_returned), len(self.node_ids))

        for node_id in self.node_ids:
            assert_in(node_id, nodes_returned)

        self.linked_node2.remove_contributor(user, auth=self.auth)
        self.public_node.remove_contributor(user, auth=self.auth)

        res = self.app.get(
            '/{}registrations/{}/linked_nodes/'.format(API_BASE, new_linking_registration._id),
            auth=user.auth
        )
        nodes_returned = [linked_node['id'] for linked_node in res.json['data']]
        assert_equal(len(nodes_returned), len(self.node_ids) - 1)

        assert_in(self.linked_node._id, nodes_returned)
        assert_in(self.public_node._id, nodes_returned)
        assert_not_in(self.linked_node2._id, nodes_returned)
开发者ID:alexschiller,项目名称:osf.io,代码行数:39,代码来源:test_registration_linked_nodes.py

示例2: TestNodeRelationshipNodeLinks

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_pointer [as 别名]
class TestNodeRelationshipNodeLinks(ApiTestCase):

    def setUp(self):
        super(TestNodeRelationshipNodeLinks, self).setUp()
        self.user = AuthUserFactory()
        self.user2 = AuthUserFactory()
        self.auth = Auth(self.user)
        self.linking_node_source = NodeFactory(creator=self.user)
        self.admin_node = NodeFactory(creator=self.user)
        self.contributor_node = NodeFactory(creator=self.user2)
        self.contributor_node.add_contributor(self.user, auth=Auth(self.user2))
        self.contributor_node.save()
        self.other_node = NodeFactory()
        self.private_node = NodeFactory(creator=self.user)
        self.public_node = NodeFactory(is_public=True)
        self.linking_node_source.add_pointer(self.private_node, auth=self.auth)
        self.linking_node_source.add_pointer(self.admin_node, auth=self.auth)
        self.public_linking_node_source = NodeFactory(is_public=True, creator=self.user2)
        self.public_linking_node_source.add_pointer(self.private_node, auth=Auth(self.user2))
        self.public_linking_node_source.add_pointer(self.public_node, auth=Auth(self.user2))
        self.public_linking_node = RegistrationFactory(project=self.public_linking_node_source, is_public=True, creator=self.user2)
        self.linking_node = RegistrationFactory(project=self.linking_node_source, creator=self.user)
        self.url = '/{}registrations/{}/relationships/linked_nodes/'.format(API_BASE, self.linking_node._id)
        self.public_url = '/{}registrations/{}/relationships/linked_nodes/'.format(API_BASE, self.public_linking_node._id)

    def payload(self, node_ids=None):
        node_ids = node_ids or [self.admin_node._id]
        env_linked_nodes = [{"type": "linked_nodes", "id": node_id} for node_id in node_ids]
        return {"data": env_linked_nodes}

    def test_get_relationship_linked_nodes(self):
        res = self.app.get(
            self.url, auth=self.user.auth
        )

        assert_equal(res.status_code, 200)

        assert_in(self.linking_node.linked_nodes_self_url, res.json['links']['self'])
        assert_in(self.linking_node.linked_nodes_related_url, res.json['links']['html'])
        assert_equal(res.json['data'][0]['id'], self.private_node._id)

    def test_get_public_relationship_linked_nodes_logged_out(self):
        res = self.app.get(self.public_url)

        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), 1)
        assert_equal(res.json['data'][0]['id'], self.public_node._id)

    def test_get_public_relationship_linked_nodes_logged_in(self):
        res = self.app.get(self.public_url, auth=self.user.auth)

        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), 2)

    def test_get_private_relationship_linked_nodes_logged_out(self):
        res = self.app.get(self.url, expect_errors=True)

        assert_equal(res.status_code, 401)

    def test_post_contributing_node(self):
        res = self.app.post_json_api(
            self.url, self.payload([self.contributor_node._id]),
            auth=self.user.auth, expect_errors=True
        )

        assert_equal(res.status_code, 405)

    def test_post_public_node(self):
        res = self.app.post_json_api(
            self.url, self.payload([self.public_node._id]),
            auth=self.user.auth, expect_errors=True
        )

        assert_equal(res.status_code, 405)

    def test_post_private_node(self):
        res = self.app.post_json_api(
            self.url, self.payload([self.other_node._id]),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equal(res.status_code, 405)

        res = self.app.get(
            self.url, auth=self.user.auth
        )

        ids = [data['id'] for data in res.json['data']]
        assert_not_in(self.other_node._id, ids)
        assert_in(self.private_node._id, ids)

    def test_post_mixed_nodes(self):
        res = self.app.post_json_api(
            self.url, self.payload([self.other_node._id, self.contributor_node._id]),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equal(res.status_code, 405)
#.........这里部分代码省略.........
开发者ID:alexschiller,项目名称:osf.io,代码行数:103,代码来源:test_registration_linked_nodes.py

示例3: TestNodeLinkedNodes

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_pointer [as 别名]
class TestNodeLinkedNodes(ApiTestCase):
    def setUp(self):
        super(TestNodeLinkedNodes, self).setUp()
        self.user = AuthUserFactory()
        self.auth = Auth(self.user)
        self.linking_node_source = NodeFactory(creator=self.user)
        self.linked_node = NodeFactory(creator=self.user)
        self.linked_node2 = NodeFactory(creator=self.user)
        self.public_node = NodeFactory(is_public=True, creator=self.user)
        self.linking_node_source.add_pointer(self.linked_node, auth=self.auth)
        self.linking_node_source.add_pointer(self.linked_node2, auth=self.auth)
        self.linking_node_source.add_pointer(self.public_node, auth=self.auth)
        self.linking_node_source.save()
        self.linking_node = RegistrationFactory(project=self.linking_node_source, creator=self.user)

        self.url = '/{}registrations/{}/linked_nodes/'.format(API_BASE, self.linking_node._id)
        self.node_ids = [pointer.node._id for pointer in self.linking_node.nodes_pointer]

    def test_linked_nodes_returns_everything(self):
        res = self.app.get(self.url, auth=self.user.auth)

        assert_equal(res.status_code, 200)
        nodes_returned = [linked_node['id'] for linked_node in res.json['data']]
        assert_equal(len(nodes_returned), len(self.node_ids))

        for node_id in self.node_ids:
            assert_in(node_id, nodes_returned)

    def test_linked_nodes_only_return_viewable_nodes(self):
        user = AuthUserFactory()
        new_linking_node = NodeFactory(creator=user)
        self.linked_node.add_contributor(user, auth=self.auth, save=True)
        self.linked_node2.add_contributor(user, auth=self.auth, save=True)
        self.public_node.add_contributor(user, auth=self.auth, save=True)
        new_linking_node.add_pointer(self.linked_node, auth=Auth(user))
        new_linking_node.add_pointer(self.linked_node2, auth=Auth(user))
        new_linking_node.add_pointer(self.public_node, auth=Auth(user))
        new_linking_node.save()
        new_linking_registration = RegistrationFactory(project=new_linking_node, creator=self.user)

        res = self.app.get(
            '/{}registrations/{}/linked_nodes/'.format(API_BASE, new_linking_registration._id),
            auth=user.auth
        )

        assert_equal(res.status_code, 200)
        nodes_returned = [linked_node['id'] for linked_node in res.json['data']]
        assert_equal(len(nodes_returned), len(self.node_ids))

        for node_id in self.node_ids:
            assert_in(node_id, nodes_returned)

        self.linked_node2.remove_contributor(user, auth=self.auth)
        self.public_node.remove_contributor(user, auth=self.auth)

        res = self.app.get(
            '/{}registrations/{}/linked_nodes/'.format(API_BASE, new_linking_registration._id),
            auth=user.auth
        )
        nodes_returned = [linked_node['id'] for linked_node in res.json['data']]
        assert_equal(len(nodes_returned), len(self.node_ids) - 1)

        assert_in(self.linked_node._id, nodes_returned)
        assert_in(self.public_node._id, nodes_returned)
        assert_not_in(self.linked_node2._id, nodes_returned)

    def test_linked_nodes_doesnt_return_deleted_nodes(self):
        self.linked_node.is_deleted = True
        self.linked_node.save()
        res = self.app.get(self.url, auth=self.user.auth)

        assert_equal(res.status_code, 200)
        nodes_returned = [linked_node['id'] for linked_node in res.json['data']]
        assert_equal(len(nodes_returned), len(self.node_ids) - 1)

        assert_not_in(self.linked_node._id, nodes_returned)
        assert_in(self.linked_node2._id, nodes_returned)
        assert_in(self.public_node._id, nodes_returned)

    def test_attempt_to_return_linked_nodes_logged_out(self):
        res = self.app.get(
            self.url, auth=None,
            expect_errors=True
        )

        assert_equal(res.status_code, 401)
开发者ID:alexschiller,项目名称:osf.io,代码行数:88,代码来源:test_registration_linked_nodes.py

示例4: TestNodeRelationshipNodeLinks

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import add_pointer [as 别名]
class TestNodeRelationshipNodeLinks(ApiTestCase):

    def setUp(self):
        super(TestNodeRelationshipNodeLinks, self).setUp()
        self.user = AuthUserFactory()
        self.user2 = AuthUserFactory()
        self.auth = Auth(self.user)
        self.linking_node = NodeFactory(creator=self.user)
        self.admin_node = NodeFactory(creator=self.user)
        self.contributor_node = NodeFactory(creator=self.user2)
        self.contributor_node.add_contributor(self.user, auth=Auth(self.user2))
        self.contributor_node.save()
        self.other_node = NodeFactory()
        self.private_node = NodeFactory(creator=self.user)
        self.public_node = NodeFactory(is_public=True)
        self.linking_node.add_pointer(self.private_node, auth=self.auth)
        self.public_linking_node = NodeFactory(is_public=True, creator=self.user2)
        self.public_linking_node.add_pointer(self.private_node, auth=Auth(self.user2))
        self.public_linking_node.add_pointer(self.public_node, auth=Auth(self.user2))
        self.url = '/{}nodes/{}/relationships/linked_nodes/'.format(API_BASE, self.linking_node._id)
        self.public_url = '/{}nodes/{}/relationships/linked_nodes/'.format(API_BASE, self.public_linking_node._id)

    def payload(self, node_ids=None):
        node_ids = node_ids or [self.admin_node._id]
        env_linked_nodes = [{'type': 'linked_nodes', 'id': node_id} for node_id in node_ids]
        return {"data": env_linked_nodes}

    def test_get_relationship_linked_nodes(self):
        res = self.app.get(
            self.url, auth=self.user.auth
        )

        assert_equal(res.status_code, 200)

        assert_in(self.linking_node.linked_nodes_self_url, res.json['links']['self'])
        assert_in(self.linking_node.linked_nodes_related_url, res.json['links']['html'])
        assert_equal(res.json['data'][0]['id'], self.private_node._id)

    def test_get_public_relationship_linked_nodes_logged_out(self):
        res = self.app.get(self.public_url)

        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), 1)
        assert_equal(res.json['data'][0]['id'], self.public_node._id)

    def test_get_public_relationship_linked_nodes_logged_in(self):
        res = self.app.get(self.public_url, auth=self.user.auth)

        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), 2)

    def test_get_private_relationship_linked_nodes_logged_out(self):
        res = self.app.get(self.url, expect_errors=True)

        assert_equal(res.status_code, 401)

    def test_post_contributing_node(self):
        res = self.app.post_json_api(
            self.url, self.payload([self.contributor_node._id]),
            auth=self.user.auth
        )

        assert_equal(res.status_code, 201)

        ids = [data['id'] for data in res.json['data']]
        assert_in(self.contributor_node._id, ids)
        assert_in(self.private_node._id, ids)

    def test_post_public_node(self):
        res = self.app.post_json_api(
            self.url, self.payload([self.public_node._id]),
            auth=self.user.auth
        )

        assert_equal(res.status_code, 201)

        ids = [data['id'] for data in res.json['data']]
        assert_in(self.public_node._id, ids)
        assert_in(self.private_node._id, ids)

    def test_post_private_node(self):
        res = self.app.post_json_api(
            self.url, self.payload([self.other_node._id]),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equal(res.status_code, 403)

        res = self.app.get(
            self.url, auth=self.user.auth
        )

        ids = [data['id'] for data in res.json['data']]
        assert_not_in(self.other_node._id, ids)
        assert_in(self.private_node._id, ids)

    def test_post_mixed_nodes(self):
        res = self.app.post_json_api(
            self.url, self.payload([self.other_node._id, self.contributor_node._id]),
#.........这里部分代码省略.........
开发者ID:alexschiller,项目名称:osf.io,代码行数:103,代码来源:test_node_linked_nodes.py


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