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


Python NodeFactory.remove_contributor方法代码示例

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


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

示例1: TestNodeLinkedNodes

# 需要导入模块: from tests.factories import NodeFactory [as 别名]
# 或者: from tests.factories.NodeFactory import remove_contributor [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


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