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


Python AuthUserFactory.add_addon方法代码示例

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


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

示例1: test_revoke_didnt_award

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

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

    def setUp(self):
        super(TestGoogleDriveHgridViews, self).setUp()
        self.user = AuthUserFactory()
        self.user.add_addon('googledrive')
        self.project = ProjectFactory(creator=self.user)
        self.project.add_addon('googledrive', Auth(self.user))
        self.node_settings = self.project.get_addon('googledrive')
        self.user_settings = self.user.get_addon('googledrive')
        self.node_settings.user_settings = self.user_settings
        self.user_settings.save()
        self.node_settings.save()
        # Log user in
        self.app.authenticate(*self.user.auth)

    @mock.patch('website.addons.googledrive.views.hgrid.GoogleDriveClient.folders')
    def test_googledrive_folders(self, mock_drive_client_folders):
        folderId = '12345'
        mock_drive_client_folders.return_value = mock_folders['items']
        url = api_url_for('googledrive_folders', pid=self.project._primary_key, folderId=folderId)
        res = self.app.get(url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json), len(mock_folders['items']))

    @mock.patch('website.addons.googledrive.views.hgrid.GoogleDriveClient.about')
    def test_googledrive_folders_returns_only_root(self, mock_about):
        mock_about.return_value = {'rootFolderId': '24601'}

        url = self.project.api_url_for('googledrive_folders')
        res = self.app.get(url, auth=self.user.auth)

        assert_equal(len(res.json), 1)
        assert_equal(res.status_code, 200)
        assert_equal(res.json[0]['id'], '24601')
开发者ID:KerryKDiehl,项目名称:osf.io,代码行数:37,代码来源:test_views.py

示例3: test_set_user_config_fail

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import add_addon [as 别名]
    def test_set_user_config_fail(self, mock_connection):

        mock_connection.side_effect = UnauthorizedError('Bad credentials!')

        # Create a user with no settings
        user = AuthUserFactory()
        user.add_addon('dataverse')
        user_settings = user.get_addon('dataverse')

        url = api_url_for('dataverse_set_user_config')
        params = {'api_token': 'wrong-info'}

        # Post incorrect credentials to existing user
        res = self.app.post_json(url, params, auth=self.user.auth,
                                 expect_errors=True)
        self.user_settings.reload()

        # Original user's info has not changed
        assert_equal(res.status_code, http.UNAUTHORIZED)
        assert_equal(self.user_settings.api_token, 'snowman-frosty')

        # Post incorrect credentials to new user
        res = self.app.post_json(url, params, auth=user.auth,
                                 expect_errors=True)
        user_settings.reload()

        # New user's incorrect credentials were not saved
        assert_equal(res.status_code, http.UNAUTHORIZED)
        assert_equal(user_settings.api_token, None)
开发者ID:crystallss,项目名称:osf.io,代码行数:31,代码来源:test_views.py

示例4: test_oauth_delete_user_two_osf_user

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import add_addon [as 别名]
    def test_oauth_delete_user_two_osf_user(self, mock_revoke_token, mock_github_user):
        mock_revoke_token.return_value = True
        user = mock.Mock()
        user.id = "testing user id"
        user.login = "testing user"
        mock_github_user.return_value = user
        views.auth.create_and_attach_oauth(self.user_settings, "testing acess token", "testing token type")

        user2 = AuthUserFactory()
        user2.add_addon('github')
        user2.save()
        user_settings2 = user2.get_addon('github')
        views.auth.create_and_attach_oauth(user_settings2, "testing access token", "testing token type")

        url = api_url_for("github_oauth_delete_user")
        self.app.delete(url, auth=self.user.auth)
        self.user_settings.reload()
        user_settings2.reload()
        assert_false(self.user_settings.oauth_token_type)
        assert_false(self.user_settings.oauth_access_token)
        assert_false(self.user_settings.github_user_name)
        assert_false(self.user_settings.oauth_settings)
        assert_true(user_settings2.oauth_settings)
        assert_equal(user_settings2.oauth_token_type, "testing token type")
        assert_equal(user_settings2.oauth_access_token, "testing access token")
        assert_equal(user_settings2.github_user_name, "testing user")
开发者ID:lbanner,项目名称:osf.io,代码行数:28,代码来源:test_views.py

示例5: TestDataverseRestrictions

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

    def setUp(self):

        super(DataverseAddonTestCase, self).setUp()

        # Nasty contributor who will try to access content that he shouldn't
        # have access to
        self.contrib = AuthUserFactory()
        self.project.add_contributor(self.contrib, auth=Auth(self.user))
        self.project.save()

    @mock.patch('addons.dataverse.views.client.connect_from_settings')
    def test_restricted_set_dataset_not_owner(self, mock_connection):
        mock_connection.return_value = create_mock_connection()

        # Contributor has dataverse auth, but is not the node authorizer
        self.contrib.add_addon('dataverse')
        self.contrib.save()

        url = api_url_for('dataverse_set_config', pid=self.project._primary_key)
        params = {
            'dataverse': {'alias': 'ALIAS1'},
            'dataset': {'doi': 'doi:12.3456/DVN/00002'},
        }
        res = self.app.post_json(url, params, auth=self.contrib.auth,
                                 expect_errors=True)
        assert_equal(res.status_code, http.FORBIDDEN)
开发者ID:adlius,项目名称:osf.io,代码行数:30,代码来源:test_views.py

示例6: TestBadge

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

    def setUp(self):
        super(TestBadge, self).setUp()
        self.user = AuthUserFactory()
        self.user.add_addon('badges', override=True)
        self.usersettings = self.user.get_addon('badges', self.user.auth)
        self.usersettings.save()

    def test_fields(self):
        badgedata = create_badge_dict()
        create_mock_badge(self.usersettings, badge_data=badgedata)
        badge = self.usersettings.badges[0]
        assert_equals(badge.name, badgedata['badgeName'])
        assert_equals(badge.description, badgedata['description'])
        assert_equals(badge.image, 'temp.png')
        assert_equals(badge.criteria, badgedata['criteria'])

    def test_system_badge(self):
        create_mock_badge(self.usersettings)
        badge = self.usersettings.badges[0]
        badge.make_system_badge()
        assert_true(badge.is_system_badge)
        assert_equals(badge, Badge.get_system_badges()[0])

    def test_assertions(self):
        create_mock_badge(self.usersettings)
        badge = self.usersettings.badges[0]
        assert_equals(len(badge.assertions), 0)
        for n in xrange(4):
            BadgeAssertion.create(badge, None)
            assert_equals(len(badge.assertions), n + 1)
开发者ID:545zhou,项目名称:osf.io,代码行数:34,代码来源:test_models.py

示例7: TestAuthViews

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

    def setUp(self):
        self.app = TestApp(app)
        self.user = AuthUserFactory()
        self.app.authenticate(*self.user.auth)


    def test_mendeley_oauth_start(self):
        self.user.add_addon('mendeley')
        settings = self.user.get_addon('mendeley')
        settings.access_token = '12345abc'
        print settings.has_auth
        settings.save()
       # assert_true(settings.has_auth)
        url = views.mendeley_oauth_start(self)
        print url



    def test_mendeley_oauth_delete_user(self):
        pass

    def test_mendeley_oauth_delete_node(self):
        pass

    def test_mendeley_oauth_callback(self):
        pass
开发者ID:retroam,项目名称:mendeley,代码行数:30,代码来源:test_views.py

示例8: TestBoxIntegration

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

    def setUp(self):
        super(TestBoxIntegration, self).setUp()
        self.user = AuthUserFactory()
        # User is logged in
        self.app.authenticate(*self.user.auth)

    def test_cant_start_oauth_if_already_authorized(self):
        # User already has box authorized
        self.user.add_addon('box')
        self.user.save()
        settings = self.user.get_addon('box')
        oauth = BoxOAuthSettings(user_id='fa;l', access_token='a;lkjadl;kas')
        oauth.save()
        settings.oauth_settings = oauth
        settings.save()

        assert_true(self.user.get_addon('box').has_auth)
        # Tries to start oauth again
        url = api_url_for('box_oauth_start_user')
        res = self.app.get(url).follow()

        # Is redirected back to settings page
        assert_equal(
            res.request.path,
            web_url_for('user_addons')
        )
开发者ID:GageGaskins,项目名称:osf.io,代码行数:30,代码来源:test_webtests.py

示例9: test_set_config_not_owner

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import add_addon [as 别名]
 def test_set_config_not_owner(self, mock_metadata):
     mock_metadata.return_value = {
         'data': {
             'name': 'Fake Folder'
         }
     }
     user = AuthUserFactory()
     user.add_addon('zotero')
     self.project.add_contributor(user)
     self.project.save()
     res = self.app.put_json(
         self.project.api_url_for('zotero_set_config'),
         {
             'external_account_id': self.account._id,
             'external_list_id': 'list',
         },
         auth=user.auth,
     )
     self.node_addon.reload()
     assert_equal(self.user_addon, self.node_addon.user_settings)
     serializer = ZoteroSerializer(node_settings=self.node_addon, user_settings=None)
     result = {
         'result': serializer.serialized_node_settings
     }
     assert_equal(res.json, result)
开发者ID:GageGaskins,项目名称:osf.io,代码行数:27,代码来源:test_views.py

示例10: TestUserSettingsModel

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

    def setUp(self):
        super(TestUserSettingsModel, self).setUp()
        self.user = AuthUserFactory()
        self.user.add_addon('badges', override=True)
        self.usersettings = self.user.get_addon('badges')
        self.usersettings.save()

    def test_can_award(self):
        assert_false(self.usersettings.can_award)
        create_mock_badge(self.usersettings)
        assert_true(self.usersettings.can_award)

    def test_to_openbadge(self):
        self.user.fullname = 'HoneyBadger'
        self.user.username = '[email protected]'
        self.user.save()

        test = {
            'name': 'HoneyBadger',
            'email': '[email protected]'
        }

        assert_equal(self.usersettings.to_openbadge(), test)

    def test_badges(self):
        create_mock_badge(self.usersettings)
        create_mock_badge(self.usersettings)
        assert_equal(len(self.usersettings.badges), 2)
        create_mock_badge(self.usersettings)
        assert_equal(len(self.usersettings.badges), 3)
开发者ID:545zhou,项目名称:osf.io,代码行数:34,代码来源:test_models.py

示例11: TestMenbibAuthViews

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

    def setUp(self):
        self.app = TestApp(app)
        self.user = AuthUserFactory()
        self.app.authenticate(*self.user.auth)

    def test_menbib_oauth_start(self):
        url = api_url_for('menbib_oauth_start_user')
        res = self.app.get(url)
        assert_is_redirect(res)

    @mock.patch('website.addons.menbib.views.auth.finish_auth')
    def test_menbib_oauth_finish(self, mock_finish):
        mock_finish.return_value = AuthResult('mytokenabc', 'myrefreshabc', 'cool', '3600')
        url = api_url_for('menbib_oauth_finish')
        res = self.app.get(url)
        assert_is_redirect(res)

    def test_menbib_oauth_delete_user(self):
        self.user.add_addon('menbib')
        user_settings = self.user.get_addon('menbib')
        user_settings.access_token = '12345abc'
        assert_true(user_settings.has_auth)
        self.user.save()
        url = api_url_for('menbib_oauth_delete_user')
        res = self.app.delete(url)
        user_settings.reload()
        assert_false(user_settings.has_auth)
开发者ID:retroam,项目名称:menbib,代码行数:31,代码来源:test_views.py

示例12: test_set_user_config_fail

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import add_addon [as 别名]
    def test_set_user_config_fail(self, mock_connection):

        mock_connection.return_value = create_mock_connection('wrong', 'info')

        # Create a user with no settings
        user = AuthUserFactory()
        user.add_addon('dataverse')
        user_settings = user.get_addon('dataverse')

        url = api_url_for('dataverse_set_user_config')
        params = {'dataverse_username': 'wrong',
                  'dataverse_password': 'info'}

        # Post incorrect credentials to existing user
        res = self.app.post_json(url, params, auth=self.user.auth,
                                 expect_errors=True)
        self.user_settings.reload()

        # Original user's info has not changed
        assert_equal(res.status_code, http.UNAUTHORIZED)
        assert_equal(self.user_settings.dataverse_username, 'snowman')
        assert_equal(self.user_settings.dataverse_password, 'frosty')

        # Post incorrect credentials to new user
        res = self.app.post_json(url, params, auth=user.auth,
                                 expect_errors=True)
        user_settings.reload()

        # New user's incorrect credentials were not saved
        assert_equal(res.status_code, http.UNAUTHORIZED)
        assert_equal(user_settings.dataverse_username, None)
        assert_equal(user_settings.dataverse_password, None)
开发者ID:KerryKDiehl,项目名称:osf.io,代码行数:34,代码来源:test_views.py

示例13: TestAssertion

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

    def setUp(self):
        super(TestAssertion, self).setUp()
        self.user = AuthUserFactory()
        self.user.add_addon('badges', override=True)
        self.usersettings = self.user.get_addon('badges', self.user.auth)
        self.usersettings.save()
        self.project = ProjectFactory()
        self.node_settings = self.project.get_addon('badges')
        create_mock_badge(self.usersettings)
        self.badge = self.usersettings.badges[0]

    def test_parent(self):
        assertion = BadgeAssertion.create(self.badge, self.project)
        assert_equals(assertion.badge, self.badge)

    def test_recipient(self):
        assertion = BadgeAssertion.create(self.badge, self.project)
        test_data = {
            'idenity': self.project._id,
            'type': 'osfnode',
            'hashed': False
        }
        assert_equals(assertion.recipient, test_data)

    def test_awarder(self):
        assertion = BadgeAssertion.create(self.badge, self.project)
        assert_equals(assertion.awarder, self.usersettings)
开发者ID:545zhou,项目名称:osf.io,代码行数:31,代码来源:test_models.py

示例14: test_many_users_each_with_the_same_github

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import add_addon [as 别名]
 def test_many_users_each_with_the_same_github(self):
     user = AuthUserFactory()
     user.add_addon('github')
     user.external_accounts.append(self.oauth_settings)
     user.save()
     results = AddonSnapshot().get_events()
     github_res = [res for res in results if res['provider']['name'] == 'github'][0]
     assert_equal(github_res['users']['total'], 2)
开发者ID:cslzchen,项目名称:osf.io,代码行数:10,代码来源:test_addon_snapshot.py

示例15: test_s3_set_bucket_no_auth

# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import add_addon [as 别名]
    def test_s3_set_bucket_no_auth(self):

        user = AuthUserFactory()
        user.add_addon("s3")
        self.project.add_contributor(user, save=True)
        url = self.project.api_url_for("s3_post_node_settings")
        res = self.app.post_json(url, {"s3_bucket": "hammertofall"}, auth=user.auth, expect_errors=True)
        assert_equal(res.status_code, http.BAD_REQUEST)
开发者ID:KAsante95,项目名称:osf.io,代码行数:10,代码来源:test_view.py


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