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


Python UserFactory.add_addon方法代码示例

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


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

示例1: test_migration

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

        user = UserFactory()
        node = ProjectFactory(creator=user)
        account = BoxAccountFactory()

        user.external_accounts = [account]

        user.add_addon('box', auth=Auth(user))
        user_addon = user.get_addon('box')
        user_addon.save()


        node.add_addon('box', auth=Auth(user))
        node_addon = node.get_addon('box')
        node_addon.foreign_user_settings = user_addon
        node_addon.folder_id = 'abcdef0'
        node_addon.folder_path = '/'
        node_addon.folder_name = '/ (Full Box)'
        node_addon.save()

        assert_equal(node_addon.external_account, None)
        assert_equal(node_addon.folder_id, 'abcdef0')

        do_migration()
        node_addon.reload()

        assert_equal(node_addon.external_account, account)
        assert_equal(node_addon.folder_id, 'abcdef0')
        assert_equal(node_addon.folder_path, '/')
        assert_equal(node_addon.folder_name, '/ (Full Box)')
开发者ID:545zhou,项目名称:osf.io,代码行数:34,代码来源:test_box_connect_external_accounts.py

示例2: TestNodeSettings

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import add_addon [as 别名]
class TestNodeSettings(OsfTestCase):
    def setUp(self):
        super(TestNodeSettings, self).setUp()
        self.user = UserFactory()
        self.project = ProjectFactory(creator=self.user)

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

        self.user_settings = self.user.get_addon('s3')
        self.node_settings = self.project.get_addon('s3')

        self.user_settings.access_key = 'We-Will-Rock-You'
        self.user_settings.secret_key = 'Idontknowanyqueensongs'
        self.user_settings.save()

        self.node_settings.bucket = 'Sheer-Heart-Attack'
        self.node_settings.user_settings = self.user_settings
        self.node_settings.save()

    def test_complete_true(self):
        assert_true(self.node_settings.has_auth)
        assert_true(self.node_settings.complete)

    def test_complete_false(self):
        self.node_settings.bucket = None

        assert_true(self.node_settings.has_auth)
        assert_false(self.node_settings.complete)

    def test_complete_auth_false(self):
        self.node_settings.user_settings = None

        assert_false(self.node_settings.has_auth)
        assert_false(self.node_settings.complete)
开发者ID:XTech2K,项目名称:osf.io,代码行数:37,代码来源:test_model.py

示例3: TestCallbacks

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import add_addon [as 别名]
class TestCallbacks(OsfTestCase):
    def setUp(self):
        super(TestCallbacks, self).setUp()

        self.user = UserFactory()
        self.user.add_addon('twofactor')
        self.user_settings = self.user.get_addon('twofactor')

    def test_add_to_user(self):
        assert_equal(self.user_settings.totp_drift, 0)
        assert_is_not_none(self.user_settings.totp_secret)
        assert_false(self.user_settings.is_confirmed)

    def test_remove_from_unconfirmed_user(self):
        # drift defaults to 0. Change it so we can test it was changed back.
        self.user_settings.totp_drift = 1
        self.user_settings.save()

        self.user.delete_addon('twofactor')

        assert_equal(self.user_settings.totp_drift, 0)
        assert_is_none(self.user_settings.totp_secret)
        assert_false(self.user_settings.is_confirmed)

    def test_remove_from_confirmed_user(self):
        # drift defaults to 0. Change it so we can test it was changed back.
        self.user_settings.totp_drift = 1
        self.user_settings.is_confirmed = True
        self.user_settings.save()

        self.user.delete_addon('twofactor')

        assert_equal(self.user_settings.totp_drift, 0)
        assert_is_none(self.user_settings.totp_secret)
        assert_false(self.user_settings.is_confirmed)
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:37,代码来源:test_models.py

示例4: TestGithubNodeSettings

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

    def setUp(self):
        OsfTestCase.setUp(self)
        self.user = UserFactory()
        self.user.add_addon('github')
        self.user_settings = self.user.get_addon('github')
        self.external_account = GitHubAccountFactory()
        self.user_settings.owner.external_accounts.append(self.external_account)
        self.user_settings.owner.save()
        self.node_settings = GitHubNodeSettingsFactory(user_settings=self.user_settings)

    @mock.patch('website.addons.github.api.GitHubClient.delete_hook')
    def test_delete_hook(self, mock_delete_hook):
        self.node_settings.hook_id = 'hook'
        self.node_settings.save()
        args = (
            self.node_settings.user,
            self.node_settings.repo,
            self.node_settings.hook_id,
        )
        res = self.node_settings.delete_hook()
        assert_true(res)
        mock_delete_hook.assert_called_with(*args)

    @mock.patch('website.addons.github.api.GitHubClient.delete_hook')
    def test_delete_hook_no_hook(self, mock_delete_hook):
        res = self.node_settings.delete_hook()
        assert_false(res)
        assert_false(mock_delete_hook.called)

    @mock.patch('website.addons.github.api.GitHubClient.delete_hook')
    def test_delete_hook_not_found(self, mock_delete_hook):
        self.node_settings.hook_id = 'hook'
        self.node_settings.save()
        mock_delete_hook.side_effect = NotFoundError
        args = (
            self.node_settings.user,
            self.node_settings.repo,
            self.node_settings.hook_id,
        )
        res = self.node_settings.delete_hook()
        assert_false(res)
        mock_delete_hook.assert_called_with(*args)

    @mock.patch('website.addons.github.api.GitHubClient.delete_hook')
    def test_delete_hook_error(self, mock_delete_hook):
        self.node_settings.hook_id = 'hook'
        self.node_settings.save()
        mock_delete_hook.side_effect = GitHubError(mock.Mock())
        args = (
            self.node_settings.user,
            self.node_settings.repo,
            self.node_settings.hook_id,
        )
        res = self.node_settings.delete_hook()
        assert_false(res)
        mock_delete_hook.assert_called_with(*args)
开发者ID:545zhou,项目名称:osf.io,代码行数:60,代码来源:test_models.py

示例5: test_to_json_noauthorizing_authed_user

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import add_addon [as 别名]
    def test_to_json_noauthorizing_authed_user(self):
        user = UserFactory()
        user.add_addon('github')
        user_settings = user.get_addon('github')

        oauth_settings = AddonGitHubOauthSettings(oauth_access_token='foobar')
        oauth_settings.github_user_id = 'testuser'
        oauth_settings.save()

        user_settings.oauth_settings = self.oauth_settings
        user_settings.save()

        self.node_settings.to_json(user)
开发者ID:AllisonLBowers,项目名称:osf.io,代码行数:15,代码来源:test_models.py

示例6: test_must_be_authorizer_false

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

        # Setup
        self.project.add_addon('github', auth=None)
        node_settings = self.project.get_addon('github')
        user2 = UserFactory()
        user2.add_addon('github')
        user_settings = user2.get_addon('github')
        node_settings.user_settings = user_settings

        # Test
        with assert_raises(HTTPError):
            self.decorated()
开发者ID:erinmayhood,项目名称:osf.io,代码行数:15,代码来源:test_auth.py

示例7: TestCore

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import add_addon [as 别名]
class TestCore(OsfTestCase):
    def setUp(self):
        self.user = UserFactory()
        self.user.add_addon('menbib')
        self.user.save()

        self.settings = self.user.get_addon('menbib')
        self.settings.access_token = '12345'
        self.settings.refresh_token = 'abcde'
        self.settings.save()

    def test_get_addon_returns_menbib_user_settings(self):
        result = self.user.get_addon('menbib')
        assert_true(isinstance(result, AddonMenbibUserSettings))
开发者ID:retroam,项目名称:menbib,代码行数:16,代码来源:test_client.py

示例8: test_migration_no_account

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

        user = UserFactory()
        node = ProjectFactory(creator=user)

        user.add_addon('box', auth=Auth(user))
        user_addon = user.get_addon('box')
        user_addon.save()

        node.add_addon('box', auth=Auth(user))
        node_addon = node.get_addon('box')
        node_addon.foreign_user_settings = user_addon
        node_addon.save()

        do_migration()  # Would raise exception if fail
开发者ID:545zhou,项目名称:osf.io,代码行数:18,代码来源:test_box_connect_external_accounts.py

示例9: TestCore

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

    def setUp(self):

        super(TestCore, self).setUp()

        self.user = UserFactory()
        self.user.add_addon('box')
        self.user.save()

        self.settings = self.user.get_addon('box')
        self.settings.save()

    def test_get_addon_returns_box_user_settings(self):
        result = self.user.get_addon('box')
        assert_true(isinstance(result, BoxUserSettings))
开发者ID:XTech2K,项目名称:osf.io,代码行数:18,代码来源:test_client.py

示例10: TestCore

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import add_addon [as 别名]
class TestCore(unittest.TestCase):

    def setUp(self):

        super(TestCore, self).setUp()

        self.user = UserFactory()
        self.user.add_addon('dropbox')
        self.user.save()

        self.settings = self.user.get_addon('dropbox')
        self.settings.access_token = '12345'
        self.settings.save()

    def test_get_addon_returns_dropbox_user_settings(self):
        result = self.user.get_addon('dropbox')
        assert_true(isinstance(result, UserSettings))
开发者ID:adlius,项目名称:osf.io,代码行数:19,代码来源:test_client.py

示例11: test_migration_no_project

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

        user = UserFactory()

        user.add_addon('googledrive')
        user_addon = user.get_addon('googledrive')
        user_addon.oauth_settings = GoogleDriveOAuthSettingsFactory()
        user_addon.save()

        do_migration([user_addon])
        user_addon.reload()

        assert_is_none(user_addon.oauth_settings)
        assert_equal(len(user.external_accounts), 1)

        account = user.external_accounts[0]
        assert_equal(account.provider, 'googledrive')
        assert_equal(account.oauth_key, 'abcdef1')
开发者ID:545zhou,项目名称:osf.io,代码行数:20,代码来源:test_googledrive_migrate_to_external_account.py

示例12: TestCallbacks

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import add_addon [as 别名]
class TestCallbacks(OsfTestCase):
    @mock.patch('website.addons.twofactor.models.push_status_message')
    def setUp(self, mocked):
        super(TestCallbacks, self).setUp()

        self.user = UserFactory()
        self.user.add_addon('twofactor')
        self.user_settings = self.user.get_addon('twofactor')
        self.on_add_called = mocked.called

    def test_add_to_user(self):
        assert_equal(self.user_settings.totp_drift, 0)
        assert_is_not_none(self.user_settings.totp_secret)
        assert_false(self.user_settings.is_confirmed)
        assert_true(self.on_add_called)

    @mock.patch('website.addons.twofactor.models.push_status_message')
    def test_remove_from_unconfirmed_user(self, mocked):
        # drift defaults to 0. Change it so we can test it was changed back.
        self.user_settings.totp_drift = 1
        self.user_settings.save()

        self.user.delete_addon('twofactor')

        assert_equal(self.user_settings.totp_drift, 0)
        assert_is_none(self.user_settings.totp_secret)
        assert_false(self.user_settings.is_confirmed)
        assert_false(mocked.called)

    @mock.patch('website.addons.twofactor.models.push_status_message')
    def test_remove_from_confirmed_user(self, mocked):
        # drift defaults to 0. Change it so we can test it was changed back.
        self.user_settings.totp_drift = 1
        self.user_settings.is_confirmed = True
        self.user_settings.save()

        self.user.delete_addon('twofactor')

        assert_equal(self.user_settings.totp_drift, 0)
        assert_is_none(self.user_settings.totp_secret)
        assert_false(self.user_settings.is_confirmed)
        assert_true(mocked.called)
开发者ID:KerryKDiehl,项目名称:osf.io,代码行数:44,代码来源:test_models.py

示例13: test_migration_no_project

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

        user = UserFactory()
        api_token = 'api-token-2345'

        user.add_addon('dataverse')
        user_addon = user.get_addon('dataverse')
        user_addon.api_token = api_token
        user_addon.save()

        do_migration([user_addon], dry=False)
        user_addon.reload()

        assert_is_none(user_addon.api_token)
        assert_equal(len(user_addon.external_accounts), 1)

        account = user_addon.external_accounts[0]
        assert_equal(account.provider, 'dataverse')
        assert_equal(account.oauth_key, 'dataverse.harvard.edu')
        assert_equal(account.oauth_secret, api_token)
开发者ID:adlius,项目名称:osf.io,代码行数:22,代码来源:test_dataverse_migrate_to_external_account.py

示例14: test_migration_includes_project

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

        user = UserFactory()
        project = ProjectFactory(creator=user)
        api_token = 'api-token-2345'

        user.add_addon('dataverse', auth=Auth(user))
        user_addon = user.get_addon('dataverse')
        user_addon.api_token = api_token
        user_addon.save()

        project.add_addon('dataverse', auth=Auth(user))
        node_addon = project.get_addon('dataverse')
        node_addon.user_settings = user_addon
        node_addon.save()

        do_migration([user_addon], dry=False)
        user_addon.reload()
        node_addon.reload()

        account = user_addon.external_accounts[0]
        assert_equal(account, node_addon.external_account)
开发者ID:adlius,项目名称:osf.io,代码行数:24,代码来源:test_dataverse_migrate_to_external_account.py

示例15: test_migration_multiple_users

# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import add_addon [as 别名]
    def test_migration_multiple_users(self):
        user1 = UserFactory()
        user2 = UserFactory()
        oauth_settings = GoogleDriveOAuthSettingsFactory()

        user1.add_addon('googledrive')
        user1_addon = user1.get_addon('googledrive')
        user1_addon.oauth_settings = oauth_settings
        user1_addon.save()

        user2.add_addon('googledrive')
        user2_addon = user2.get_addon('googledrive')
        user2_addon.oauth_settings = oauth_settings
        user2_addon.save()

        do_migration([user1_addon, user2_addon])
        user1_addon.reload()
        user2_addon.reload()

        assert_equal(
            user1.external_accounts[0],
            user2.external_accounts[0],
        )
开发者ID:545zhou,项目名称:osf.io,代码行数:25,代码来源:test_googledrive_migrate_to_external_account.py


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