本文整理汇总了Python中tests.factories.UserFactory.get_addon方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.get_addon方法的具体用法?Python UserFactory.get_addon怎么用?Python UserFactory.get_addon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.get_addon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestCore
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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))
示例2: TestCore
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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))
示例3: test_migration
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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)')
示例4: TestNodeSettings
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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)
示例5: TestCallbacks
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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)
示例6: TestCore
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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))
示例7: TestGithubNodeSettings
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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)
示例8: test_to_json_noauthorizing_authed_user
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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)
示例9: test_must_be_authorizer_false
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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()
示例10: test_migration_multiple_users
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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],
)
示例11: test_migration_multiple_users
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_addon [as 别名]
def test_migration_multiple_users(self):
user1 = UserFactory()
user2 = UserFactory()
api_token = 'api-token-2345'
user1.add_addon('dataverse')
user1_addon = user1.get_addon('dataverse')
user1_addon.api_token = api_token
user1_addon.save()
user2.add_addon('dataverse')
user2_addon = user2.get_addon('dataverse')
user2_addon.api_token = api_token
user2_addon.save()
do_migration([user1_addon, user2_addon], dry=False)
user1_addon.reload()
user2_addon.reload()
assert_equal(
user1_addon.external_accounts[0],
user2_addon.external_accounts[0],
)
示例12: test_migration_no_account
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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
示例13: test_migration_no_project
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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')
示例14: TestCallbacks
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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)
示例15: test_migration_no_project
# 需要导入模块: from tests.factories import UserFactory [as 别名]
# 或者: from tests.factories.UserFactory import get_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)