本文整理汇总了Python中osf_tests.factories.UserFactory.add_addon方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.add_addon方法的具体用法?Python UserFactory.add_addon怎么用?Python UserFactory.add_addon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类osf_tests.factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.add_addon方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGithubNodeSettings
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import add_addon [as 别名]
class TestGithubNodeSettings(unittest.TestCase):
def setUp(self):
super(TestGithubNodeSettings, self).setUp()
self.user = UserFactory()
self.user.add_addon('github')
self.user_settings = self.user.get_addon('github')
self.external_account = factories.GitHubAccountFactory()
self.user_settings.owner.external_accounts.add(self.external_account)
self.user_settings.owner.save()
self.node_settings = factories.GitHubNodeSettingsFactory(user_settings=self.user_settings)
@mock.patch('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('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('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('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)
示例2: test_must_be_authorizer_false
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_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
node_settings.save()
# Test
with assert_raises(HTTPError):
self.decorated()
示例3: TestCore
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_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('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, UserSettings))
示例4: TestGitLabNodeSettings
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import add_addon [as 别名]
class TestGitLabNodeSettings(unittest.TestCase):
def setUp(self):
super(TestGitLabNodeSettings, self).setUp()
self.user = UserFactory()
self.user.add_addon('gitlab')
self.user_settings = self.user.get_addon('gitlab')
self.external_account = GitLabAccountFactory()
self.user_settings.owner.external_accounts.add(self.external_account)
self.user_settings.owner.save()
self.node_settings = GitLabNodeSettingsFactory(user_settings=self.user_settings)
@mock.patch('addons.gitlab.api.GitLabClient.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)
示例5: TestCallbacks
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import add_addon [as 别名]
class TestCallbacks(unittest.TestCase):
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')
self.user_settings.reload()
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')
self.user_settings.reload()
assert_equal(self.user_settings.totp_drift, 0)
assert_is_none(self.user_settings.totp_secret)
assert_false(self.user_settings.is_confirmed)
示例6: TestUserSettingsModel
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import add_addon [as 别名]
class TestUserSettingsModel(unittest.TestCase):
TOTP_SECRET = 'b8f85986068f8079aa9d'
TOTP_SECRET_B32 = 'XD4FTBQGR6AHTKU5'
def setUp(self):
super(TestUserSettingsModel, self).setUp()
self.user = UserFactory()
self.user.add_addon('twofactor')
self.user_settings = self.user.get_addon('twofactor')
self.user_settings.totp_secret = self.TOTP_SECRET
self.user_settings.save()
def tearDown(self):
super(TestUserSettingsModel, self).tearDown()
self.user.__class__.delete(self.user)
def test_b32(self):
assert_equal(self.user_settings.totp_secret_b32, self.TOTP_SECRET_B32)
def test_otpauth_url(self):
url = urlparse(self.user_settings.otpauth_url)
assert_equal(url.scheme, 'otpauth')
assert_equal(url.netloc, 'totp')
assert_equal(url.path, '/OSF:{}'.format(self.user.username))
assert_equal(
parse_qs(url.query),
{'secret': [self.TOTP_SECRET_B32]}
)
def test_json(self):
# url = 'otpauth://totp/OSF:{}?secret=' + self.TOTP_SECRET_B32
settings = self.user_settings.to_json(user=None)
assert_equal(
settings,
{
'is_enabled': True,
'addon_full_name': 'Two-factor Authentication',
'addon_short_name': 'twofactor',
'drift': 0,
'is_confirmed': False,
'nodes': [],
'secret': self.TOTP_SECRET_B32,
'has_auth': False,
}
)
def test_verify_valid_code(self):
assert_true(
self.user_settings.verify_code(_valid_code(self.TOTP_SECRET))
)
def test_verify_valid_core_drift(self):
# use a code from 30 seconds in the future
assert_true(
self.user_settings.verify_code(
_valid_code(self.TOTP_SECRET, drift=1)
)
)
# make sure drift is updated.
assert_equal(self.user_settings.totp_drift, 1)
# use a code from 60 seconds in the future
assert_true(
self.user_settings.verify_code(
_valid_code(self.TOTP_SECRET, drift=2)
)
)
# make sure drift is updated.
assert_equal(self.user_settings.totp_drift, 2)
# use the current code (which is now 2 periods away from the drift)
assert_false(
self.user_settings.verify_code(_valid_code(self.TOTP_SECRET))
)
示例7: user
# 需要导入模块: from osf_tests.factories import UserFactory [as 别名]
# 或者: from osf_tests.factories.UserFactory import add_addon [as 别名]
def user(self):
ret = UserFactory()
ret.add_addon('onedrive')
ret.save()
return ret