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


Python ProjectFactory.rm_pointer方法代码示例

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


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

示例1: TestNodeForkCreate

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import rm_pointer [as 别名]

#.........这里部分代码省略.........
        assert_equal(res.status_code, 201)
        assert_equal(res.json['data']['id'], self.public_project.forks[0]._id)
        assert_equal(res.json['data']['attributes']['title'], 'Fork of ' + self.public_project.title)

    def test_cannot_fork_public_node_logged_out(self):
        res = self.app.post_json_api(self.public_project_url, self.fork_data, expect_errors=True)
        assert_equal(res.status_code, 401)
        assert_equal(res.json['errors'][0]['detail'], 'Authentication credentials were not provided.')

    def test_can_fork_public_node_logged_in_contributor(self):
        res = self.app.post_json_api(self.public_project_url, self.fork_data, auth=self.user.auth)
        assert_equal(res.status_code, 201)
        assert_equal(res.json['data']['id'], self.public_project.forks[0]._id)
        assert_equal(res.json['data']['attributes']['title'], 'Fork of ' + self.public_project.title)

    def test_cannot_fork_private_node_logged_out(self):
        res = self.app.post_json_api(self.private_project_url, self.fork_data, expect_errors=True)
        assert_equal(res.status_code, 401)
        assert_equal(res.json['errors'][0]['detail'], 'Authentication credentials were not provided.')

    def test_cannot_fork_private_node_logged_in_non_contributor(self):
        res = self.app.post_json_api(self.private_project_url, self.fork_data, auth=self.user_two.auth, expect_errors=True)
        assert_equal(res.status_code, 403)
        assert_equal(res.json['errors'][0]['detail'], 'You do not have permission to perform this action.')

    def test_can_fork_private_node_logged_in_contributor(self):
        res = self.app.post_json_api(self.private_project_url + '?embed=children&embed=node_links&embed=logs&embed=contributors&embed=forked_from', self.fork_data, auth=self.user.auth)
        assert_equal(res.status_code, 201)

        data = res.json['data']
        assert_equal(data['attributes']['title'], 'Fork of ' + self.private_project.title)

        fork_contributors = data['embeds']['contributors']['data'][0]['embeds']['users']['data']
        assert_equal(fork_contributors['attributes']['family_name'], self.user.family_name)
        assert_equal(fork_contributors['id'], self.user._id)

        forked_from = data['embeds']['forked_from']['data']
        assert_equal(forked_from['id'], self.private_project._id)

    def test_fork_private_components_no_access(self):
        url = self.public_project_url + '?embed=children'
        private_component = NodeFactory(parent=self.public_project, creator=self.user_two, is_public=False)
        res = self.app.post_json_api(url, self.fork_data, auth=self.user_three.auth)
        assert_equal(res.status_code, 201)
        # Private components that you do not have access to are not forked
        assert_equal(res.json['data']['embeds']['children']['links']['meta']['total'], 0)

    def test_fork_components_you_can_access(self):
        url = self.private_project_url + '?embed=children'
        new_component = NodeFactory(parent=self.private_project, creator=self.user)
        res = self.app.post_json_api(url, self.fork_data, auth=self.user.auth)
        assert_equal(res.status_code, 201)
        assert_equal(res.json['data']['embeds']['children']['links']['meta']['total'], 1)
        assert_equal(res.json['data']['embeds']['children']['data'][0]['id'], new_component.forks[0]._id)

    def test_fork_private_node_links(self):
        private_pointer = ProjectFactory(creator=self.user_two)
        actual_pointer = self.private_project.add_pointer(private_pointer, auth=Auth(self.user_two), save=True)

        url = self.private_project_url + '?embed=node_links'

        # Node link is forked, but shows up as a private node link
        res = self.app.post_json_api(url, self.fork_data, auth=self.user.auth)
        assert_equal(res.status_code, 201)

        assert_equal(res.json['data']['embeds']['node_links']['data'][0]['embeds']['target_node']['errors'][0]['detail'],
                     'You do not have permission to perform this action.')
        assert_equal(res.json['data']['embeds']['node_links']['links']['meta']['total'], 1)

        self.private_project.rm_pointer(actual_pointer, auth=Auth(self.user_two))

    def test_fork_node_links_you_can_access(self):
        pointer = ProjectFactory(creator=self.user)
        self.private_project.add_pointer(pointer, auth=Auth(self.user_two), save=True)

        url = self.private_project_url + '?embed=node_links'

        res = self.app.post_json_api(url, self.fork_data, auth=self.user.auth)
        assert_equal(res.status_code, 201)

        assert_equal(res.json['data']['embeds']['node_links']['data'][0]['embeds']['target_node']['data']['id'], pointer._id)
        assert_equal(res.json['data']['embeds']['node_links']['links']['meta']['total'], 1)

    def test_can_fork_registration(self):
        registration = RegistrationFactory(project=self.private_project, user=self.user)

        url = '/{}registrations/{}/forks/'.format(API_BASE, registration._id)
        res = self.app.post_json_api(url, self.fork_data, auth=self.user.auth)
        assert_equal(res.status_code, 201)
        assert_equal(res.json['data']['id'], registration.forks[0]._id)
        assert_equal(res.json['data']['attributes']['title'], 'Fork of ' + registration.title)

    def test_read_only_contributor_can_fork_private_registration(self):
        read_only_user = AuthUserFactory()

        self.private_project.add_contributor(read_only_user, permissions=[permissions.READ], save=True)
        res = self.app.post_json_api(self.private_project_url, self.fork_data, auth=read_only_user.auth)
        assert_equal(res.status_code, 201)
        assert_equal(res.json['data']['id'], self.private_project.forks[0]._id)
        assert_equal(res.json['data']['attributes']['title'], 'Fork of ' + self.private_project.title)
开发者ID:HalcyonChimera,项目名称:osf.io,代码行数:104,代码来源:test_node_forks_list.py


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