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


Python factories.PrivateLinkFactory类代码示例

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


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

示例1: TestPrivateLink

class TestPrivateLink(OsfTestCase):

    def setUp(self):
        super(TestPrivateLink, self).setUp()
        self.flaskapp = Flask('testing_private_links')

        @self.flaskapp.route('/project/<pid>/')
        @must_be_contributor
        def project_get(**kwargs):
            return 'success', 200

        self.app = WebtestApp(self.flaskapp)

        self.user = AuthUserFactory()
        self.project = ProjectFactory(is_public=False)
        self.link = PrivateLinkFactory()
        self.link.nodes.add(self.project)
        self.link.save()

    @mock.patch('website.project.decorators.Auth.from_kwargs')
    def test_has_private_link_key(self, mock_from_kwargs):
        mock_from_kwargs.return_value = Auth(user=None)
        res = self.app.get('/project/{0}'.format(self.project._primary_key),
            {'view_only': self.link.key})
        res = res.follow()
        assert_equal(res.status_code, 200)
        assert_equal(res.body, 'success')

    @mock.patch('website.project.decorators.Auth.from_kwargs')
    def test_does_not_have_key(self, mock_from_kwargs):
        mock_from_kwargs.return_value = Auth(user=None)
        res = self.app.get('/project/{0}'.format(self.project._primary_key),
            {'key': None})
        assert_is_redirect(res)
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:34,代码来源:test_auth.py

示例2: setUp

    def setUp(self):
        super(TestMustBeContributorOrPublicButNotAnonymizedDecorator, self).setUp()
        self.contrib = AuthUserFactory()
        self.non_contrib = AuthUserFactory()
        admin = UserFactory()
        self.public_project = ProjectFactory(is_public=True)
        self.public_project.add_contributor(admin, auth=Auth(self.public_project.creator), permissions=['read', 'write', 'admin'])
        self.private_project = ProjectFactory(is_public=False)
        self.private_project.add_contributor(admin, auth=Auth(self.private_project.creator), permissions=['read', 'write', 'admin'])
        self.public_project.add_contributor(self.contrib, auth=Auth(self.public_project.creator))
        self.private_project.add_contributor(self.contrib, auth=Auth(self.private_project.creator))
        self.public_project.save()
        self.private_project.save()
        self.anonymized_link_to_public_project = PrivateLinkFactory(anonymous=True)
        self.anonymized_link_to_private_project = PrivateLinkFactory(anonymous=True)
        self.anonymized_link_to_public_project.nodes.add(self.public_project)
        self.anonymized_link_to_public_project.save()
        self.anonymized_link_to_private_project.nodes.add(self.private_project)
        self.anonymized_link_to_private_project.save()
        self.flaskapp = Flask('Testing decorator')

        @self.flaskapp.route('/project/<pid>/')
        @must_be_contributor_or_public_but_not_anonymized
        def project_get(**kwargs):
            return 'success', 200
        self.app = WebtestApp(self.flaskapp)
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:26,代码来源:test_auth.py

示例3: test_private_node_user_with_view_only_link_can_view_wiki_version

 def test_private_node_user_with_view_only_link_can_view_wiki_version(self):
     self._set_up_private_project_with_wiki_page()
     private_link = PrivateLinkFactory(anonymous=False)
     private_link.nodes.add(self.private_project)
     private_link.save()
     url = furl.furl(self.private_url).add(query_params={'view_only': private_link.key}).url
     res = self.app.get(url)
     assert_equal(res.status_code, 200)
     assert_equal(res.json['data']['id'], str(self.private_wiki_version.identifier))
开发者ID:erinspace,项目名称:osf.io,代码行数:9,代码来源:test_wiki_version_detail.py

示例4: TestPrivateLinkView

class TestPrivateLinkView(OsfTestCase):

    def setUp(self):
        super(TestPrivateLinkView, self).setUp()
        self.user = AuthUserFactory()  # Is NOT a contributor
        self.project = ProjectFactory(is_public=False)
        self.link = PrivateLinkFactory(anonymous=True)
        self.link.nodes.add(self.project)
        self.link.save()
        self.project_url = self.project.web_url_for('view_project')

    def test_anonymous_link_hide_contributor(self):
        res = self.app.get(self.project_url, {'view_only': self.link.key})
        assert_in('Anonymous Contributors', res.body)
        assert_not_in(self.user.fullname, res)

    def test_anonymous_link_hides_citations(self):
        res = self.app.get(self.project_url, {'view_only': self.link.key})
        assert_not_in('Citation:', res)

    def test_no_warning_for_read_only_user_with_valid_link(self):
        link2 = PrivateLinkFactory(anonymous=False)
        link2.nodes.add(self.project)
        link2.save()
        self.project.add_contributor(
            self.user,
            permissions=['read'],
            save=True,
        )
        res = self.app.get(self.project_url, {'view_only': link2.key},
                           auth=self.user.auth)
        assert_not_in(
            'is being viewed through a private, view-only link. '
            'Anyone with the link can view this project. Keep '
            'the link safe.',
            res.body
        )

    def test_no_warning_for_read_only_user_with_invalid_link(self):
        self.project.add_contributor(
            self.user,
            permissions=['read'],
            save=True,
        )
        res = self.app.get(self.project_url, {'view_only': 'not_valid'},
                           auth=self.user.auth)
        assert_not_in(
            'is being viewed through a private, view-only link. '
            'Anyone with the link can view this project. Keep '
            'the link safe.',
            res.body
        )
开发者ID:erinspace,项目名称:osf.io,代码行数:52,代码来源:test_webtests.py

示例5: test_build_addon_root_for_anonymous_vols_hides_path

    def test_build_addon_root_for_anonymous_vols_hides_path(self):
        private_anonymous_link = PrivateLinkFactory(anonymous=True)
        private_anonymous_link.nodes.add(self.project)
        private_anonymous_link.save()
        project_viewer = UserFactory()

        result = rubeus.build_addon_root(
            self.node_settings,
            self.node_settings.bucket,
            user=project_viewer,
            private_key=private_anonymous_link.key
        )

        assert result['name'] == 'Amazon S3'
开发者ID:adlius,项目名称:osf.io,代码行数:14,代码来源:test_rubeus.py

示例6: test_params_do_not_appear_on_private_project_with_anonymous_view_only_link

    def test_params_do_not_appear_on_private_project_with_anonymous_view_only_link(self):

        private_link = PrivateLinkFactory(anonymous=True)
        private_link.nodes.add(self.node)
        private_link.save()

        url = self.url + '{}/'.format(self.log_add_contributor._id)

        res = self.app.get(url, {'view_only': private_link.key}, expect_errors=True)
        assert_equal(res.status_code, 200)
        data = res.json['data']
        assert_in('attributes', data)
        assert_not_in('params', data['attributes'])
        body = res.body
        assert_not_in(self.user._id, body)
开发者ID:adlius,项目名称:osf.io,代码行数:15,代码来源:test_log_params.py

示例7: test_params_do_not_appear_on_private_project_with_anonymous_view_only_link

    def test_params_do_not_appear_on_private_project_with_anonymous_view_only_link(
            self, app, url_logs, node_private, contributor_log_private, user_one):

        private_link = PrivateLinkFactory(anonymous=True)
        private_link.nodes.add(node_private)
        private_link.save()

        url = '{}{}/'.format(url_logs, contributor_log_private._id)

        res = app.get(url, {'view_only': private_link.key}, expect_errors=True)
        assert res.status_code == 200
        data = res.json['data']
        assert 'attributes' in data
        assert 'params' not in data['attributes']
        body = res.body
        assert user_one._id not in body
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:16,代码来源:test_log_params.py

示例8: test_no_warning_for_read_only_user_with_valid_link

 def test_no_warning_for_read_only_user_with_valid_link(self):
     link2 = PrivateLinkFactory(anonymous=False)
     link2.nodes.add(self.project)
     link2.save()
     self.project.add_contributor(
         self.user,
         permissions=['read'],
         save=True,
     )
     res = self.app.get(self.project_url, {'view_only': link2.key},
                        auth=self.user.auth)
     assert_not_in(
         'is being viewed through a private, view-only link. '
         'Anyone with the link can view this project. Keep '
         'the link safe.',
         res.body
     )
开发者ID:erinspace,项目名称:osf.io,代码行数:17,代码来源:test_webtests.py

示例9: setUp

 def setUp(self):
     super(TestPrivateLinkView, self).setUp()
     self.user = AuthUserFactory()  # Is NOT a contributor
     self.project = ProjectFactory(is_public=False)
     self.link = PrivateLinkFactory(anonymous=True)
     self.link.nodes.add(self.project)
     self.link.save()
     self.project_url = self.project.web_url_for('view_project')
开发者ID:erinspace,项目名称:osf.io,代码行数:8,代码来源:test_webtests.py

示例10: test_deleted_vols_not_returned

    def test_deleted_vols_not_returned(self, app, user, url, public_project):
        view_only_link = PrivateLinkFactory(name='testlink2')
        view_only_link.nodes.add(public_project)
        view_only_link.save()

        res = app.get(url, auth=user.auth)
        data = res.json['data']
        assert res.status_code == 200
        assert len(data) == 2

        view_only_link.nodes.remove(public_project)
        view_only_link.save()

        res = app.get(url, auth=user.auth)
        data = res.json['data']
        assert res.status_code == 200
        assert len(data) == 1
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:17,代码来源:test_node_view_only_links_list.py

示例11: test_public_node_deleted_comments_auth_misc

    def test_public_node_deleted_comments_auth_misc(
            self, app, user, contributor, non_contrib,
            public_project, public_comment
    ):
        public_comment.is_deleted = True
        public_comment.save()
        url = '/{}comments/{}/'.format(API_BASE, public_comment._id)

        # test_public_node_only_logged_in_commenter_can_view_deleted_comment
        res = app.get(url, auth=user.auth)
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] == public_comment.content

        # test_public_node_contributor_cannot_view_other_users_deleted_comment

        res = app.get(url, auth=contributor.auth)
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] is None

        # test_public_node_non_contrib_cannot_view_other_users_deleted_comment
        res = app.get(url, auth=non_contrib.auth)
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] is None

        # test_public_node_logged_out_user_cannot_view_deleted_comments
        res = app.get(url)
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] is None

        # test_public_node_view_only_link_user_cannot_see_deleted_comment
        private_link = PrivateLinkFactory(anonymous=False)
        private_link.nodes.add(public_project)
        private_link.save()

        res = app.get(
            '/{}comments/{}/'.format(
                API_BASE, public_comment._id
            ),
            {'view_only': private_link.key},
            expect_errors=True
        )
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] is None
开发者ID:erinspace,项目名称:osf.io,代码行数:43,代码来源:test_comment_detail.py

示例12: test_redirects_through_view_only_link

    def test_redirects_through_view_only_link(self, app, project, user):

        # test_redirect_when_viewing_private_project_through_view_only_link
        view_only_link = PrivateLinkFactory(anonymous=False)
        view_only_link.nodes.add(project)
        view_only_link.save()

        url = '/{}guids/{}/?view_only={}'.format(
            API_BASE, project._id, view_only_link.key)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}nodes/{}/?view_only={}'.format(
            API_DOMAIN, API_BASE, project._id, view_only_link.key)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_when_viewing_private_project_file_through_view_only_link
        test_file = OsfStorageFile.create(
            node=project,
            path='/test',
            name='test',
            materialized_path='/test',
        )
        test_file.save()
        guid = test_file.get_guid(create=True)
        url = '/{}guids/{}/?view_only={}'.format(
            API_BASE, guid._id, view_only_link.key)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}files/{}/?view_only={}'.format(
            API_DOMAIN, API_BASE, test_file._id, view_only_link.key)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_when_viewing_private_project_comment_through_view_only_link
        comment = CommentFactory(node=project)
        url = '/{}guids/{}/?view_only={}'.format(
            API_BASE, comment._id, view_only_link.key)
        res = app.get(url, auth=AuthUserFactory().auth)
        redirect_url = '{}{}comments/{}/?view_only={}'.format(
            API_DOMAIN, API_BASE, comment._id, view_only_link.key)
        assert res.status_code == 302
        assert res.location == redirect_url
开发者ID:leb2dg,项目名称:osf.io,代码行数:41,代码来源:test_guid_detail.py

示例13: test_public_node_comment_can_view_misc

    def test_public_node_comment_can_view_misc(
            self, app, user, non_contrib,
            public_project, public_url,
            public_comment, registration_comment,
            comment_url
    ):
        # test_public_node_logged_in_contributor_can_view_comment
        res = app.get(public_url, auth=user.auth)
        assert res.status_code == 200
        assert public_comment._id == res.json['data']['id']
        assert public_comment.content == res.json['data']['attributes']['content']

        # test_public_node_logged_in_non_contrib_can_view_comment
        res = app.get(public_url, auth=non_contrib.auth)
        assert res.status_code == 200
        assert public_comment._id == res.json['data']['id']
        assert public_comment.content == res.json['data']['attributes']['content']

        # test_public_node_logged_out_user_can_view_comment
        res = app.get(public_url)
        assert res.status_code == 200
        assert public_comment._id == res.json['data']['id']
        assert public_comment.content == res.json['data']['attributes']['content']

        # test_registration_logged_in_contributor_can_view_comment
        res = app.get(comment_url, auth=user.auth)
        assert res.status_code == 200
        assert registration_comment._id == res.json['data']['id']
        assert registration_comment.content == res.json['data']['attributes']['content']

        # test_public_node_user_with_private_link_can_view_comment
        private_link = PrivateLinkFactory(anonymous=False)
        private_link.nodes.add(public_project)
        private_link.save()
        res = app.get(
            '/{}comments/{}/'.format(API_BASE, public_comment._id),
            {'view_only': private_link.key}, expect_errors=True
        )
        assert public_comment._id == res.json['data']['id']
        assert public_comment.content == res.json['data']['attributes']['content']
开发者ID:erinspace,项目名称:osf.io,代码行数:40,代码来源:test_comment_detail.py

示例14: test_private_node_deleted_comment_auth_misc

    def test_private_node_deleted_comment_auth_misc(
            self, app, user, contributor, comment, private_project):
        comment.is_deleted = True
        comment.save()

        # test_private_node_only_logged_in_commenter_can_view_deleted_comment
        url = '/{}comments/{}/'.format(API_BASE, comment._id)
        res = app.get(url, auth=user.auth)
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] == comment.content

        # test_private_node_contributor_cannot_see_other_users_deleted_comment
        url = '/{}comments/{}/'.format(API_BASE, comment._id)
        res = app.get(url, auth=contributor.auth)
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] is None

        # test_private_node_logged_out_user_cannot_see_deleted_comment
        url = '/{}comments/{}/'.format(API_BASE, comment._id)
        res = app.get(url, expect_errors=True)
        assert res.status_code == 401
        assert res.json['errors'][0]['detail'] == exceptions.NotAuthenticated.default_detail

        # test_private_node_view_only_link_user_cannot_see_deleted_comment
        private_link = PrivateLinkFactory(anonymous=False)
        private_link.nodes.add(private_project)
        private_link.save()

        res = app.get('/{}comments/{}/'.format(API_BASE, comment._id),
                      {'view_only': private_link.key}, expect_errors=True)
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] is None

        # test_private_node_anonymous_view_only_link_user_cannot_see_deleted_comment
        anonymous_link = PrivateLinkFactory(anonymous=True)
        anonymous_link.nodes.add(private_project)
        anonymous_link.save()

        res = app.get('/{}comments/{}/'.format(API_BASE, comment._id),
                      {'view_only': anonymous_link.key}, expect_errors=True)
        assert res.status_code == 200
        assert res.json['data']['attributes']['content'] is None
开发者ID:erinspace,项目名称:osf.io,代码行数:42,代码来源:test_comment_detail.py

示例15: test_private_node_user_with_private_and_anonymous_link_misc

    def test_private_node_user_with_private_and_anonymous_link_misc(
            self, app, private_project, comment):
        # def test_private_node_user_with_private_link_can_see_comment
        private_link = PrivateLinkFactory(anonymous=False)
        private_link.nodes.add(private_project)
        private_link.save()
        res = app.get(
            '/{}comments/{}/'.format(API_BASE, comment._id),
            {'view_only': private_link.key}, expect_errors=True
        )
        assert res.status_code == 200
        assert comment._id == res.json['data']['id']
        assert comment.content == res.json['data']['attributes']['content']

        # test_private_node_user_with_anonymous_link_cannot_see_commenter_info
        private_link = PrivateLinkFactory(anonymous=True)
        private_link.nodes.add(private_project)
        private_link.save()
        res = app.get(
            '/{}comments/{}/'.format(API_BASE, comment._id),
            {'view_only': private_link.key}
        )
        assert res.status_code == 200
        assert comment._id == res.json['data']['id']
        assert comment.content == res.json['data']['attributes']['content']
        assert 'user' not in res.json['data']['relationships']

        # test_private_node_user_with_anonymous_link_cannot_see_mention_info
        comment.content = 'test with [@username](userlink) and @mention'
        comment.save()
        res = app.get(
            '/{}comments/{}/'.format(API_BASE, comment._id),
            {'view_only': private_link.key}
        )
        assert res.status_code == 200
        assert comment._id == res.json['data']['id']
        assert 'test with @A User and @mention' == res.json['data']['attributes']['content']
开发者ID:erinspace,项目名称:osf.io,代码行数:37,代码来源:test_comment_detail.py


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