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


Python AuthUserFactory.reload方法代码示例

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


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

示例1: test_revoke_didnt_award

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
    def test_revoke_didnt_award(self):
        badgeid = self.user_settings.badges[0]._id
        initnum = len(self.project.badgeassertion__awarded)
        assert_true(self.user_settings.can_award)
        url = api_url_for('award_badge', pid=self.project._id)
        ret = self.app.post_json(url, {'badgeid': badgeid}, auth=self.user.auth)
        self.project.reload()
        assert_equals(ret.status_int, 200)
        assert_equals(initnum + 1, len(self.project.badgeassertion__awarded))

        assertion = self.project.badgeassertion__awarded[0]

        revoke = api_url_for('revoke_badge', pid=self.project._id)

        user2 = AuthUserFactory()
        user2.add_addon('badges', override=True)
        user2.save()
        user2.reload()

        ret = self.app.post_json(revoke,
            {
                'id': assertion._id,
                'reason': ''
            }, auth=user2.auth, expect_errors=True)
        self.project.reload()
        self.user_settings.reload()
        assertion.reload()

        assert_equals(ret.status_int, 400)
        assert_false(assertion.revoked)
        assert_true(self.project.badgeassertion__awarded[0]._id, assertion._id)
        assert_false(assertion._id in self.user_settings.revocation_list)
开发者ID:AndrewSallans,项目名称:osf.io,代码行数:34,代码来源:test_views.py

示例2: test_confirm_non_contrib_viewers_dont_have_pid_in_comments_view_timestamp

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
    def test_confirm_non_contrib_viewers_dont_have_pid_in_comments_view_timestamp(self):
        non_contributor = AuthUserFactory()
        url = self.project.api_url_for("update_comments_timestamp")
        res = self.app.put_json(url, {"page": "node", "rootId": self.project._id}, auth=self.user.auth)

        non_contributor.reload()
        assert_not_in(self.project._id, non_contributor.comments_viewed_timestamp)
开发者ID:ycchen1989,项目名称:osf.io,代码行数:9,代码来源:test_comments.py

示例3: test_user_settings_when_user_does_not_have_addon

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
 def test_user_settings_when_user_does_not_have_addon(self, _):
     user = AuthUserFactory()
     url = self.project.api_url_for("s3_post_user_settings")
     self.app.post_json(url, {"access_key": "ABCDEFG", "secret_key": "We are the champions"}, auth=user.auth)
     user.reload()
     user_settings = user.get_addon("s3")
     assert_equals(user_settings.access_key, "ABCDEFG")
     assert_equals(user_settings.secret_key, "We are the champions")
开发者ID:KAsante95,项目名称:osf.io,代码行数:10,代码来源:test_view.py

示例4: TestCommentViews

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
class TestCommentViews(OsfTestCase):

    def setUp(self):
        super(TestCommentViews, self).setUp()
        self.project = ProjectFactory(is_public=True)
        self.user = AuthUserFactory()
        self.project.add_contributor(self.user)
        self.project.save()
        self.user.save()

    def test_view_project_comments_updates_user_comments_view_timestamp(self):
        url = self.project.api_url_for('update_comments_timestamp')
        res = self.app.put_json(url, {
            'page': 'node',
            'rootId': self.project._id
        }, auth=self.user.auth)
        self.user.reload()

        user_timestamp = self.user.comments_viewed_timestamp[self.project._id]['node']
        view_timestamp = dt.datetime.utcnow()
        assert_datetime_equal(user_timestamp, view_timestamp)

    def test_confirm_non_contrib_viewers_dont_have_pid_in_comments_view_timestamp(self):
        non_contributor = AuthUserFactory()
        url = self.project.api_url_for('update_comments_timestamp')
        res = self.app.put_json(url, {
            'page': 'node',
            'rootId': self.project._id
        }, auth=self.user.auth)

        non_contributor.reload()
        assert_not_in(self.project._id, non_contributor.comments_viewed_timestamp)

    def test_view_comments_updates_user_comments_view_timestamp_files(self):
        osfstorage = self.project.get_addon('osfstorage')
        root_node = osfstorage.get_root()
        test_file = root_node.append_file('test_file')
        test_file.create_version(self.user, {
            'object': '06d80e',
            'service': 'cloud',
            osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
        }, {
            'size': 1337,
            'contentType': 'img/png'
        }).save()

        url = self.project.api_url_for('update_comments_timestamp')
        res = self.app.put_json(url, {
            'page': 'files',
            'rootId': test_file._id
        }, auth=self.user.auth)
        self.user.reload()

        user_timestamp = self.user.comments_viewed_timestamp[self.project._id]['files'][test_file._id]
        view_timestamp = dt.datetime.utcnow()
        assert_datetime_equal(user_timestamp, view_timestamp)
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:58,代码来源:test_comments.py

示例5: test_user_settings_when_user_does_not_have_addon

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
 def test_user_settings_when_user_does_not_have_addon(self, _):
     user = AuthUserFactory()
     url = self.project.api_url_for('s3_post_user_settings')
     self.app.post_json(
         url,
         {
             'access_key': 'ABCDEFG',
             'secret_key': 'We are the champions'
         },
         auth=user.auth
     )
     user.reload()
     user_settings = user.get_addon('s3')
     assert_equals(user_settings.access_key, 'ABCDEFG')
     assert_equals(user_settings.secret_key, 'We are the champions')
开发者ID:XTech2K,项目名称:osf.io,代码行数:17,代码来源:test_view.py

示例6: test_merged_user

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
    def test_merged_user(self):
        user = AuthUserFactory(fullname='Annie Lennox')
        merged_user = AuthUserFactory(fullname='Lisa Stansfield')
        user.save()
        merged_user.save()

        user.merge_user(merged_user)
        user.save()
        merged_user.save()
        user.reload()
        merged_user.reload()
        modify_user_dates_in_mongo(self.yesterday)

        data = UserSummary().get_events(self.yesterday.date())[0]
        assert_equal(data['status']['merged'], 1)
开发者ID:adlius,项目名称:osf.io,代码行数:17,代码来源:test_user_summary.py

示例7: test_find_unread_includes_edited_comments

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
    def test_find_unread_includes_edited_comments(self):
        project = ProjectFactory()
        user = AuthUserFactory()
        project.add_contributor(user)
        project.save()
        comment = CommentFactory(node=project, user=project.creator)

        url = project.api_url_for("update_comments_timestamp")
        payload = {"page": "node", "rootId": project._id}
        res = self.app.put_json(url, payload, auth=user.auth)
        user.reload()
        n_unread = Comment.find_n_unread(user=user, node=project, page="node")
        assert_equal(n_unread, 0)

        # Edit previously read comment
        comment.edit(auth=Auth(project.creator), content="edited", save=True)
        n_unread = Comment.find_n_unread(user=user, node=project, page="node")
        assert_equal(n_unread, 1)
开发者ID:ycchen1989,项目名称:osf.io,代码行数:20,代码来源:test_comments.py

示例8: TestCommentViews

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
class TestCommentViews(OsfTestCase):
    def setUp(self):
        super(TestCommentViews, self).setUp()
        self.project = ProjectFactory(is_public=True)
        self.user = AuthUserFactory()
        self.project.add_contributor(self.user)
        self.project.save()
        self.user.save()

    def test_view_project_comments_updates_user_comments_view_timestamp(self):
        url = self.project.api_url_for("update_comments_timestamp")
        res = self.app.put_json(url, {"page": "node", "rootId": self.project._id}, auth=self.user.auth)
        self.user.reload()

        user_timestamp = self.user.comments_viewed_timestamp[self.project._id]
        view_timestamp = dt.datetime.utcnow()
        assert_datetime_equal(user_timestamp, view_timestamp)

    def test_confirm_non_contrib_viewers_dont_have_pid_in_comments_view_timestamp(self):
        non_contributor = AuthUserFactory()
        url = self.project.api_url_for("update_comments_timestamp")
        res = self.app.put_json(url, {"page": "node", "rootId": self.project._id}, auth=self.user.auth)

        non_contributor.reload()
        assert_not_in(self.project._id, non_contributor.comments_viewed_timestamp)

    def test_view_comments_updates_user_comments_view_timestamp_files(self):
        osfstorage = self.project.get_addon("osfstorage")
        root_node = osfstorage.get_root()
        test_file = root_node.append_file("test_file")
        test_file.create_version(
            self.user,
            {"object": "06d80e", "service": "cloud", osfstorage_settings.WATERBUTLER_RESOURCE: "osf"},
            {"size": 1337, "contentType": "img/png"},
        ).save()

        url = self.project.api_url_for("update_comments_timestamp")
        res = self.app.put_json(url, {"page": "files", "rootId": test_file._id}, auth=self.user.auth)
        self.user.reload()

        user_timestamp = self.user.comments_viewed_timestamp[test_file._id]
        view_timestamp = dt.datetime.utcnow()
        assert_datetime_equal(user_timestamp, view_timestamp)
开发者ID:ycchen1989,项目名称:osf.io,代码行数:45,代码来源:test_comments.py

示例9: TestForgotAndResetPasswordViews

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
class TestForgotAndResetPasswordViews(OsfTestCase):

    def setUp(self):
        super(TestForgotAndResetPasswordViews, self).setUp()
        self.user = AuthUserFactory()
        self.key = random_string(20)
        # manually set verifification key
        self.user.verification_key = self.key
        self.user.save()

        self.url = web_url_for('reset_password', verification_key=self.key)

    def test_reset_password_view_returns_200(self):
        res = self.app.get(self.url)
        assert_equal(res.status_code, 200)

    def test_can_reset_password_if_form_success(self):
        res = self.app.get(self.url)
        form = res.forms['resetPasswordForm']
        form['password'] = 'newpassword'
        form['password2'] = 'newpassword'
        res = form.submit()

        # password was updated
        self.user.reload()
        assert_true(self.user.check_password('newpassword'))

    @unittest.skip('TODO: Get this working with CAS setup')
    def test_reset_password_logs_out_user(self):
        another_user = AuthUserFactory()
        # visits reset password link while another user is logged in
        res = self.app.get(self.url, auth=another_user.auth)
        assert_equal(res.status_code, 200)
        # We check if another_user is logged in by checking if
        # their full name appears on the page (it should be in the navbar).
        # Yes, this is brittle.
        assert_not_in(another_user.fullname, res)
        # make sure the form is on the page
        assert_true(res.forms['resetPasswordForm'])
开发者ID:billyhunt,项目名称:osf.io,代码行数:41,代码来源:webtest_tests.py

示例10: TestResetPassword

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
class TestResetPassword(OsfTestCase):

    def setUp(self):
        super(TestResetPassword, self).setUp()
        self.user = AuthUserFactory()
        self.another_user = AuthUserFactory()
        self.osf_key_v2 = generate_verification_key(verification_type='password')
        self.user.verification_key_v2 = self.osf_key_v2
        self.user.verification_key = None
        self.user.save()
        self.get_url = web_url_for(
            'reset_password_get',
            uid=self.user._id,
            token=self.osf_key_v2['token']
        )
        self.get_url_invalid_key = web_url_for(
            'reset_password_get',
            uid=self.user._id,
            token=generate_verification_key()
        )
        self.get_url_invalid_user = web_url_for(
            'reset_password_get',
            uid=self.another_user._id,
            token=self.osf_key_v2['token']
        )

    # successfully load reset password page
    def test_reset_password_view_returns_200(self):
        res = self.app.get(self.get_url)
        assert_equal(res.status_code, 200)

    # raise http 400 error
    def test_reset_password_view_raises_400(self):
        res = self.app.get(self.get_url_invalid_key, expect_errors=True)
        assert_equal(res.status_code, 400)

        res = self.app.get(self.get_url_invalid_user, expect_errors=True)
        assert_equal(res.status_code, 400)

        self.user.verification_key_v2['expires'] = dt.datetime.utcnow()
        self.user.save()
        res = self.app.get(self.get_url, expect_errors=True)
        assert_equal(res.status_code, 400)

    # successfully reset password
    @mock.patch('framework.auth.cas.CasClient.service_validate')
    def test_can_reset_password_if_form_success(self, mock_service_validate):
        # load reset password page and submit email
        res = self.app.get(self.get_url)
        form = res.forms['resetPasswordForm']
        form['password'] = 'newpassword'
        form['password2'] = 'newpassword'
        res = form.submit()

        # check request URL is /resetpassword with username and new verification_key_v2 token
        request_url_path = res.request.path
        assert_in('resetpassword', request_url_path)
        assert_in(self.user._id, request_url_path)
        assert_not_in(self.user.verification_key_v2['token'], request_url_path)

        # check verification_key_v2 for OSF is destroyed and verification_key for CAS is in place
        self.user.reload()
        assert_equal(self.user.verification_key_v2, {})
        assert_not_equal(self.user.verification_key, None)

        # check redirection to CAS login with username and the new verification_key(CAS)
        assert_equal(res.status_code, 302)
        location = res.headers.get('Location')
        assert_true('login?service=' in location)
        assert_true('username={}'.format(self.user.username) in location)
        assert_true('verification_key={}'.format(self.user.verification_key) in location)

        # check if password was updated
        self.user.reload()
        assert_true(self.user.check_password('newpassword'))

        # check if verification_key is destroyed after service validation
        mock_service_validate.return_value = cas.CasResponse(
            authenticated=True,
            user=self.user._primary_key,
            attributes={'accessToken': fake.md5()}
        )
        ticket = fake.md5()
        service_url = 'http://accounts.osf.io/?ticket=' + ticket
        cas.make_response_from_ticket(ticket, service_url)
        assert_equal(self.user.verification_key, None)

    #  log users out before they land on reset password page
    def test_reset_password_logs_out_user(self):
        # visit reset password link while another user is logged in
        res = self.app.get(self.get_url, auth=self.another_user.auth)
        # check redirection to CAS logout
        assert_equal(res.status_code, 302)
        location = res.headers.get('Location')
        assert_not_in('reauth', location)
        assert_in('logout?service=', location)
        assert_in('resetpassword', location)
开发者ID:baylee-d,项目名称:osf.io,代码行数:99,代码来源:webtest_tests.py

示例11: TestExternalAccount

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
class TestExternalAccount(OsfTestCase):
    # Test the ExternalAccount object and associated views.
    #
    # Functionality not specific to the OAuth version used by the
    # ExternalProvider should go here.

    def setUp(self):
        super(TestExternalAccount, self).setUp()
        self.user = AuthUserFactory()
        self.provider = MockOAuth2Provider()

    def tearDown(self):
        ExternalAccount._clear_caches()
        ExternalAccount.remove()
        self.user.remove()
        super(TestExternalAccount, self).tearDown()

    def test_disconnect(self):
        # Disconnect an external account from a user
        external_account = ExternalAccountFactory(
            provider='mock2',
            provider_id='mock_provider_id',
            provider_name='Mock Provider',
        )
        self.user.external_accounts.append(external_account)
        self.user.save()

        # If the external account isn't attached, this test has no meaning
        assert_equal(ExternalAccount.find().count(), 1)
        assert_in(
            external_account,
            self.user.external_accounts,
        )

        response = self.app.delete(
            api_url_for('oauth_disconnect',
                        external_account_id=external_account._id),
            auth=self.user.auth
        )

        # Request succeeded
        assert_equal(
            response.status_code,
            http.OK,
        )

        self.user.reload()
        # external_account.reload()

        # External account has been disassociated with the user
        assert_not_in(
            external_account,
            self.user.external_accounts,
        )

        # External account is still in the database
        assert_equal(ExternalAccount.find().count(), 1)

    def test_disconnect_with_multiple_connected(self):
        # Disconnect an account connected to multiple users from one user
        external_account = ExternalAccountFactory(
            provider='mock2',
            provider_id='mock_provider_id',
            provider_name='Mock Provider',
        )
        self.user.external_accounts.append(external_account)
        self.user.save()

        other_user = UserFactory()
        other_user.external_accounts.append(external_account)
        other_user.save()

        response = self.app.delete(
            api_url_for('oauth_disconnect',
                        external_account_id=external_account._id),
            auth=self.user.auth
        )

        # Request succeeded
        assert_equal(
            response.status_code,
            http.OK,
        )

        self.user.reload()

        # External account has been disassociated with the user
        assert_not_in(
            external_account,
            self.user.external_accounts,
        )

        # External account is still in the database
        assert_equal(ExternalAccount.find().count(), 1)

        other_user.reload()

        # External account is still associated with the other user
        assert_in(
            external_account,
#.........这里部分代码省略.........
开发者ID:GageGaskins,项目名称:osf.io,代码行数:103,代码来源:test_oauth.py

示例12: TestAddonFileViews

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import reload [as 别名]
class TestAddonFileViews(OsfTestCase):

    def setUp(self):
        super(TestAddonFileViews, self).setUp()
        self.user = AuthUserFactory()
        self.project = ProjectFactory(creator=self.user)

        self.user.add_addon('github')
        self.project.add_addon('github', auth=Auth(self.user))

        self.user_addon = self.user.get_addon('github')
        self.node_addon = self.project.get_addon('github')
        self.oauth = AddonGitHubOauthSettings(
            github_user_id='denbarell',
            oauth_access_token='Truthy'
        )

        self.oauth.save()

        self.user_addon.oauth_settings = self.oauth
        self.user_addon.save()

        self.node_addon.user_settings = self.user_addon
        self.node_addon.repo = 'Truth'
        self.node_addon.user = 'E'
        self.node_addon.save()

        # self.node_addon.user_settings = 'Truthy'
        # setattr(self.node_addon, 'has_auth', True)

    def get_mako_return(self):
        ret = serialize_node(self.project, Auth(self.user), primary=True)
        ret.update({
            'error': '',
            'provider': '',
            'file_path': '',
            'sharejs_uuid': '',
            'urls': {
                'files': '',
                'render': '',
                'sharejs': '',
                'mfr': '',
                'gravatar': '',
            },
            'size': '',
            'extra': '',
            'file_name': '',
            'materialized_path': '',
        })
        ret.update(rubeus.collect_addon_assets(self.project))
        return ret

    def test_redirects_to_guid(self):
        path = 'bigdata'
        guid, _ = self.node_addon.find_or_create_file_guid('/' + path)

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github'
            ),
            auth=self.user.auth
        )

        assert_equals(resp.status_code, 302)
        assert_equals(resp.headers['Location'], 'http://localhost:80{}'.format(guid.guid_url))

    def test_action_download_redirects_to_download(self):
        path = 'cloudfiles'
        guid, _ = self.node_addon.find_or_create_file_guid('/' + path)

        resp = self.app.get(guid.guid_url + '?action=download', auth=self.user.auth)

        assert_equals(resp.status_code, 302)
        assert_equals(resp.headers['Location'], guid.download_url + '&action=download')

    @mock.patch('website.addons.base.request')
    def test_public_download_url_includes_view_only(self, mock_request):
        view_only = 'justworkplease'
        mock_request.args = {
            'view_only': view_only
        }

        path = 'cloudfiles'
        guid, _ = self.node_addon.find_or_create_file_guid('/' + path)

        assert_in('view_only={}'.format(view_only), guid.public_download_url)

    @mock.patch('website.addons.base.views.addon_view_file')
    def test_action_view_calls_view_file(self, mock_view_file):
        self.user.reload()
        self.project.reload()

        path = 'cloudfiles'
        mock_view_file.return_value = self.get_mako_return()
        guid, _ = self.node_addon.find_or_create_file_guid('/' + path)

        self.app.get(guid.guid_url + '?action=view', auth=self.user.auth)

#.........这里部分代码省略.........
开发者ID:ticklemepierce,项目名称:osf.io,代码行数:103,代码来源:test_addons.py

示例13: TestAddonFileViews

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

#.........这里部分代码省略.........
                'addon_view_or_download_file',
                path=file_node.path.strip('/'),
                provider='github'
            ),
            auth=self.user.auth
        )

        assert_equals(resp.status_code, 302)
        assert_equals(resp.location, 'http://localhost:80/{}/'.format(guid._id))

    def test_action_download_redirects_to_download(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.get('/{}/?action=download'.format(guid._id), auth=self.user.auth)

        assert_equals(resp.status_code, 302)
        location = furl.furl(resp.location)
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(action='download', direct=None, version=None))

    def test_action_download_redirects_to_download_with_version(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.get('/{}/?action=download&revision=1'.format(guid._id), auth=self.user.auth)

        assert_equals(resp.status_code, 302)
        location = furl.furl(resp.location)
        # Note: version is added but us but all other url params are added as well
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(action='download', direct=None, revision=1, version=1))

    @mock.patch('website.addons.base.views.addon_view_file')
    def test_action_view_calls_view_file(self, mock_view_file):
        self.user.reload()
        self.project.reload()

        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        mock_view_file.return_value = self.get_mako_return()

        self.app.get('/{}/?action=view'.format(guid._id), auth=self.user.auth)

        args, kwargs = mock_view_file.call_args
        assert_equals(kwargs, {})
        assert_equals(args[0].user._id, self.user._id)
        assert_equals(args[1], self.project)
        assert_equals(args[2], file_node)
        assert_true(isinstance(args[3], file_node.touch(None).__class__))

    @mock.patch('website.addons.base.views.addon_view_file')
    def test_no_action_calls_view_file(self, mock_view_file):
        self.user.reload()
        self.project.reload()

        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        mock_view_file.return_value = self.get_mako_return()

        self.app.get('/{}/'.format(guid._id), auth=self.user.auth)

        args, kwargs = mock_view_file.call_args
        assert_equals(kwargs, {})
        assert_equals(args[0].user._id, self.user._id)
        assert_equals(args[1], self.project)
开发者ID:mattspitzer,项目名称:osf.io,代码行数:70,代码来源:test_addons.py

示例14: TestUserInstititutionRelationship

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

#.........这里部分代码省略.........
    def test_delete_no_auth(self):
        res = self.app.delete_json_api(
            self.url,
            {'data': [
                {'type': 'institutions', 'id': self.institution1._id}
            ]},
            expect_errors=True
        )

        assert_equal(res.status_code, 401)

    def test_delete_wrong_auth(self):
        res = self.app.delete_json_api(
            self.url,
            {'data': [
                {'type': 'institutions', 'id': self.institution1._id}
            ]},
            auth=self.user2.auth, expect_errors=True
        )

        assert_equal(res.status_code, 403)

    def test_delete_one(self):
        res = self.app.delete_json_api(
            self.url,
            {'data': [
                {'type': 'institutions', 'id': self.institution1._id}
            ]},
            auth=self.user.auth
        )

        assert_equal(res.status_code, 204)

        self.user.reload()

        ids = [inst._id for inst in self.user.affiliated_institutions]
        assert_not_in(self.institution1._id, ids)
        assert_in(self.institution2._id, ids)

    def test_type_mistyped(self):
        res = self.app.delete_json_api(
            self.url,
            {'data': [
                {'type': 'wow', 'id': self.institution1._id}
            ]},
            auth=self.user.auth, expect_errors=True
        )

        assert_equal(res.status_code, 409)

    def test_delete_multiple(self):
        res = self.app.delete_json_api(
            self.url,
            {'data': [
                {'type': 'institutions', 'id': self.institution1._id},
                {'type': 'institutions', 'id': self.institution2._id}
            ]},
            auth=self.user.auth
        )

        assert_equal(res.status_code, 204)

        self.user.reload()

        ids = [inst._id for inst in self.user.affiliated_institutions]
        assert_not_in(self.institution1._id, ids)
开发者ID:545zhou,项目名称:osf.io,代码行数:70,代码来源:test_user_institutions_relationship.py

示例15: TestAddonFileViews

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

#.........这里部分代码省略.........
                'addon_view_or_download_file',
                path=file_node.path.strip('/'),
                provider='github'
            ),
            auth=self.user.auth
        )

        assert_equals(resp.status_code, 302)
        assert_equals(resp.location, 'http://localhost:80/{}/'.format(guid._id))

    def test_action_download_redirects_to_download(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.get('/{}/?action=download'.format(guid._id), auth=self.user.auth)

        assert_equals(resp.status_code, 302)
        location = furl.furl(resp.location)
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(action='download', direct=None, version=None))

    def test_action_download_redirects_to_download_with_version(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.get('/{}/?action=download&revision=1'.format(guid._id), auth=self.user.auth)

        assert_equals(resp.status_code, 302)
        location = furl.furl(resp.location)
        # Note: version is added but us but all other url params are added as well
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(action='download', direct=None, revision=1, version=None))

    @mock.patch('website.addons.base.views.addon_view_file')
    def test_action_view_calls_view_file(self, mock_view_file):
        self.user.reload()
        self.project.reload()

        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        mock_view_file.return_value = self.get_mako_return()

        self.app.get('/{}/?action=view'.format(guid._id), auth=self.user.auth)

        args, kwargs = mock_view_file.call_args
        assert_equals(kwargs, {})
        assert_equals(args[0].user._id, self.user._id)
        assert_equals(args[1], self.project)
        assert_equals(args[2], file_node)
        assert_true(isinstance(args[3], file_node.touch(None).__class__))

    @mock.patch('website.addons.base.views.addon_view_file')
    def test_no_action_calls_view_file(self, mock_view_file):
        self.user.reload()
        self.project.reload()

        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        mock_view_file.return_value = self.get_mako_return()

        self.app.get('/{}/'.format(guid._id), auth=self.user.auth)

        args, kwargs = mock_view_file.call_args
        assert_equals(kwargs, {})
        assert_equals(args[0].user._id, self.user._id)
        assert_equals(args[1], self.project)
开发者ID:baylee-d,项目名称:osf.io,代码行数:70,代码来源:test_addons.py


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