本文整理汇总了Python中tests.factories.AuthUserFactory.get_addon方法的典型用法代码示例。如果您正苦于以下问题:Python AuthUserFactory.get_addon方法的具体用法?Python AuthUserFactory.get_addon怎么用?Python AuthUserFactory.get_addon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.AuthUserFactory
的用法示例。
在下文中一共展示了AuthUserFactory.get_addon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBoxIntegration
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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')
)
示例2: TestAuthViews
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_addon [as 别名]
class TestAuthViews(OsfTestCase):
def setUp(self):
super(TestAuthViews, self).setUp()
self.user = AuthUserFactory()
# Log user in
self.app.authenticate(*self.user.auth)
def test_dropbox_oauth_start(self):
url = api_url_for('dropbox_oauth_start_user')
res = self.app.get(url)
assert_is_redirect(res)
assert_in('&force_reapprove=true', res.location)
@mock.patch('website.addons.dropbox.views.auth.DropboxOAuth2Flow.finish')
@mock.patch('website.addons.dropbox.views.auth.get_client_from_user_settings')
def test_dropbox_oauth_finish(self, mock_get, mock_finish):
mock_client = mock.MagicMock()
mock_client.account_info.return_value = {'display_name': 'Mr. Drop Box'}
mock_get.return_value = mock_client
mock_finish.return_value = ('mytoken123', 'mydropboxid', 'done')
url = api_url_for('dropbox_oauth_finish')
res = self.app.get(url)
assert_is_redirect(res)
@mock.patch('website.addons.dropbox.client.DropboxClient.disable_access_token')
def test_dropbox_oauth_delete_user(self, mock_disable_access_token):
self.user.add_addon('dropbox')
settings = self.user.get_addon('dropbox')
settings.access_token = '12345abc'
settings.save()
assert_true(settings.has_auth)
self.user.save()
url = api_url_for('dropbox_oauth_delete_user')
self.app.delete(url)
settings.reload()
assert_false(settings.has_auth)
@mock.patch('website.addons.dropbox.client.DropboxClient.disable_access_token')
def test_dropbox_oauth_delete_user_with_invalid_credentials(self, mock_disable_access_token):
self.user.add_addon('dropbox')
settings = self.user.get_addon('dropbox')
settings.access_token = '12345abc'
settings.save()
assert_true(settings.has_auth)
mock_response = mock.Mock()
mock_response.status = 401
mock_disable_access_token.side_effect = ErrorResponse(mock_response, "The given OAuth 2 access token doesn't exist or has expired.")
self.user.save()
url = api_url_for('dropbox_oauth_delete_user')
self.app.delete(url)
settings.reload()
assert_false(settings.has_auth)
示例3: TestMenbibAuthViews
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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)
示例4: TestAssertion
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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)
示例5: test_set_user_config_fail
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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)
示例6: TestGoogleDriveHgridViews
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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')
示例7: TestBadge
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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)
示例8: TestCreateBucket
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_addon [as 别名]
class TestCreateBucket(OsfTestCase):
def setUp(self):
super(TestCreateBucket, self).setUp()
self.user = AuthUserFactory()
self.consolidated_auth = Auth(user=self.user)
self.auth = ('test', self.user.api_keys[0]._primary_key)
self.project = ProjectFactory(creator=self.user)
self.project.add_addon('s3', auth=self.consolidated_auth)
self.project.creator.add_addon('s3')
self.user_settings = self.user.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 = self.project.get_addon('s3')
self.node_settings.bucket = 'Sheer-Heart-Attack'
self.node_settings.user_settings = self.project.creator.get_addon('s3')
self.node_settings.save()
def test_bad_names(self):
assert_false(validate_bucket_name('bogus naMe'))
assert_false(validate_bucket_name(''))
assert_false(validate_bucket_name('no'))
assert_false(validate_bucket_name('.cantstartwithp'))
assert_false(validate_bucket_name('or.endwith.'))
assert_false(validate_bucket_name('..nodoubles'))
assert_false(validate_bucket_name('no_unders_in'))
def test_names(self):
assert_true(validate_bucket_name('imagoodname'))
assert_true(validate_bucket_name('still.passing'))
assert_true(validate_bucket_name('can-have-dashes'))
assert_true(validate_bucket_name('kinda.name.spaced'))
@mock.patch('website.addons.s3.views.crud.create_bucket')
@mock.patch('website.addons.s3.utils.get_bucket_drop_down')
def test_create_bucket_pass(self, mock_make, mock_dropdown):
mock_make.return_value = True
mock_dropdown.return_value = ['mybucket']
url = self.project.api_url_for('create_new_bucket')
ret = self.app.post_json(url, {'bucket_name': 'doesntevenmatter'}, auth=self.user.auth)
assert_equals(ret.status_int, http.OK)
@mock.patch('website.addons.s3.views.crud.create_bucket')
def test_create_bucket_fail(self, mock_make):
error = S3ResponseError(418, 'because Im a test')
error.message = 'This should work'
mock_make.side_effect = error
url = "/api/v1/project/{0}/s3/newbucket/".format(self.project._id)
ret = self.app.post_json(url, {'bucket_name': 'doesntevenmatter'}, auth=self.user.auth, expect_errors=True)
assert_equals(ret.body, '{"message": "This should work", "title": "Problem connecting to S3"}')
示例9: TestUserSettingsModel
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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)
示例10: TestAuthViews
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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
示例11: test_oauth_delete_user_two_osf_user
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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")
示例12: test_set_user_config_fail
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_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)
示例13: test_user_settings_when_user_does_not_have_addon
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_addon [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")
示例14: TestGoogleDriveUtils
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_addon [as 别名]
class TestGoogleDriveUtils(OsfTestCase):
def setUp(self):
super(TestGoogleDriveUtils, 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')
oauth_settings = GoogleDriveOAuthSettingsFactory()
self.user_settings.oauth_settings = oauth_settings
self.node_settings.user_settings = self.user_settings
self.node_settings.folder_id = '09120912'
self.node_settings.folder_path = 'foo/bar'
self.user_settings.save()
self.node_settings.save()
# Log user in
self.app.authenticate(*self.user.auth)
def test_serialize_settings_helper_returns_correct_urls(self):
result = serialize_settings(self.node_settings, self.user)
urls = result['urls']
assert_equal(urls['files'], self.project.web_url_for('collect_file_trees'))
assert_equal(urls['config'], self.project.api_url_for('googledrive_config_put'))
assert_equal(urls['deauthorize'], self.project.api_url_for('googledrive_deauthorize'))
assert_equal(urls['importAuth'], self.project.api_url_for('googledrive_import_user_auth'))
# Includes endpoint for fetching folders only
# NOTE: Querystring params are in camelCase
assert_equal(urls['get_folders'], self.project.api_url_for('googledrive_folders'))
def test_serialize_settings_helper_returns_correct_auth_info(self):
self.user_settings.access_token = 'abc123'
result = serialize_settings(self.node_settings, self.user)
assert_equal(result['nodeHasAuth'], self.node_settings.has_auth)
assert_true(result['userHasAuth'])
assert_true(result['userIsOwner'])
def test_serialize_settings_for_user_no_auth(self):
no_addon_user = AuthUserFactory()
result = serialize_settings(self.node_settings, no_addon_user)
assert_false(result['userIsOwner'])
assert_false(result['userHasAuth'])
def test_googledrive_import_user_auth_returns_serialized_settings(self):
self.node_settings.user_settings = None
self.node_settings.save()
url = api_url_for('googledrive_import_user_auth', pid=self.project._primary_key)
res = self.app.put(url, auth=self.user.auth)
self.project.reload()
self.node_settings.reload()
expected_result = serialize_settings(self.node_settings, self.user)
result = res.json['result']
assert_equal(result, expected_result)
示例15: test_s3_set_bucket_already_authed
# 需要导入模块: from tests.factories import AuthUserFactory [as 别名]
# 或者: from tests.factories.AuthUserFactory import get_addon [as 别名]
def test_s3_set_bucket_already_authed(self):
user = AuthUserFactory()
user.add_addon("s3")
user_settings = user.get_addon("s3")
user_settings.access_key = "foo"
user_settings.secret_key = "bar"
user_settings.save()
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)