本文整理汇总了Python中tests.factories.ProjectFactory.add_addon方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory.add_addon方法的具体用法?Python ProjectFactory.add_addon怎么用?Python ProjectFactory.add_addon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tests.factories.ProjectFactory
的用法示例。
在下文中一共展示了ProjectFactory.add_addon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestNodeSettings
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
class TestNodeSettings(OsfTestCase):
def setUp(self):
super(TestNodeSettings, self).setUp()
self.user = AuthUserFactory()
self.project = ProjectFactory(creator=self.user)
self.project.add_addon('figshare', auth=Auth(self.user))
self.project.creator.add_addon('figshare')
self.node_settings = self.project.get_addon('figshare')
self.user_settings = self.project.creator.get_addon('figshare')
self.user_settings.oauth_access_token = 'legittoken'
self.user_settings.oauth_access_token_secret = 'legittoken'
self.user_settings.save()
self.node_settings.user_settings = self.user_settings
self.node_settings.figshare_id = '123456'
self.node_settings.figshare_type = 'project'
self.node_settings.figshare_title = 'singlefile'
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.figshare_id = 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)
示例2: TestNodeSettings
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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)
示例3: TestCreateBucket
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_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"}')
示例4: test_migration
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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)')
示例5: TestGoogleDriveHgridViews
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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')
示例6: test_oauth_callback_with_node
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
def test_oauth_callback_with_node(self, mock_get_token, mock_github_user):
mock_get_token.return_value = {
"access_token": "testing access token",
"token_type": "testing token type",
"scope": ["repo"]
}
user = mock.Mock()
user.id = "testing user id"
user.login = "testing user"
mock_github_user.return_value = user
project = ProjectFactory(creator=self.user)
project.add_addon('github', auth=Auth(user=self.user))
project.save()
url = api_url_for('github_oauth_callback', uid=self.user._id, nid=project._id)
res = self.app.get(url, {"code": "12345"}, auth=self.user.auth)
self.user_settings.reload()
node_settings = project.get_addon('github')
node_settings.reload()
assert_true(res.status_code, 302)
assert_not_in("/settings/addons/", res.location)
assert_in("/settings", res.location)
assert_true(self.user_settings.oauth_settings)
assert_equal(self.user_settings.oauth_access_token, "testing access token")
assert_equal(self.user_settings.oauth_token_type, "testing token type")
assert_equal(self.user_settings.github_user_name, "testing user")
assert_equal(self.user_settings.oauth_settings.github_user_id, "testing user id")
assert_equal(node_settings.user_settings, self.user_settings)
示例7: TestDatasetMigration
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
class TestDatasetMigration(OsfTestCase):
def setUp(self):
super(TestDatasetMigration, self).setUp()
self.project = ProjectFactory()
self.project.creator.add_addon('dataverse')
self.user_addon = self.project.creator.get_addon('dataverse')
self.project.add_addon('dataverse', None)
self.node_addon = self.project.get_addon('dataverse')
self.node_addon.study_hdl = 'doi:12.3456/DVN/00003'
self.node_addon.study = 'Example (DVN/00003)'
self.node_addon.user_settings = self.user_addon
self.node_addon.save()
def test_migration(self):
do_migration([self.node_addon], dry=False)
self.node_addon.reload()
assert_equal(self.node_addon.dataset_doi, 'doi:12.3456/DVN/00003')
assert_equal(self.node_addon.dataset, 'Example (DVN/00003)')
def test_get_targets(self):
AddonDataverseNodeSettings.remove()
addons = [
AddonDataverseNodeSettings(),
AddonDataverseNodeSettings(study_hdl='foo'),
AddonDataverseNodeSettings(user_settings=self.user_addon),
AddonDataverseNodeSettings(study_hdl='foo', user_settings=self.user_addon),
]
for addon in addons:
addon.save()
targets = get_targets()
assert_equal(targets.count(), 1)
assert_equal(targets[0]._id, addons[-1]._id)
示例8: TestHookMigration
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
class TestHookMigration(OsfTestCase):
def setUp(self):
super(TestHookMigration, self).setUp()
self.project = ProjectFactory()
self.project.creator.add_addon('github')
self.user_addon = self.project.creator.get_addon('github')
self.project.add_addon('github', None)
self.node_addon = self.project.get_addon('github')
self.node_addon.hook_id = 1
self.node_addon.user_settings = self.user_addon
self.node_addon.save()
@mock.patch('addons.github.utils.make_hook_secret')
@mock.patch('addons.github.api.GitHub.repo')
def test_update_hook(self, mock_repo, mock_make_secret):
mock_make_secret.return_value = 'shh'
update_hook(self.node_addon)
self.node_addon.reload()
assert_equal(self.node_addon.hook_secret, 'shh')
def test_get_targets(self):
AddonGitHubNodeSettings.remove()
addons = [
AddonGitHubNodeSettings(),
AddonGitHubNodeSettings(hook_id=1),
AddonGitHubNodeSettings(user_settings=self.user_addon),
AddonGitHubNodeSettings(hook_id=1, user_settings=self.user_addon),
]
for addon in addons:
addon.save()
targets = get_targets()
assert_equal(targets.count(), 1)
assert_equal(targets[0]._id, addons[-1]._id)
示例9: TestViewsAuth
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
class TestViewsAuth(OsfTestCase):
def setUp(self):
super(TestViewsAuth, 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.non_authenticator = AuthUserFactory()
self.project.add_contributor(
contributor=self.non_authenticator,
auth=Auth(self.project.creator),
)
self.project.add_addon('figshare', auth=self.consolidated_auth)
self.project.creator.add_addon('figshare')
self.node_settings = self.project.get_addon('figshare')
self.user_settings = self.project.creator.get_addon('figshare')
self.node_settings.user_settings = self.user_settings
self.node_settings.figshare_id = '436'
self.node_settings.figshare_type = 'project'
self.node_settings.save()
@unittest.skip('finish this')
def test_oauth_fail(self):
url = '/api/v1/project/{0}/figshare/oauth/'.format(self.project._id)
self.app.get(url, auth=self.user.auth)
@unittest.skip('finish this')
def test_oauth_bad_token(self):
pass
示例10: TestMustHaveAddonDecorator
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
class TestMustHaveAddonDecorator(AuthAppTestCase):
def setUp(self):
super(TestMustHaveAddonDecorator, self).setUp()
self.project = ProjectFactory()
@mock.patch('website.project.decorators._kwargs_to_nodes')
def test_must_have_addon_node_true(self, mock_kwargs_to_nodes):
mock_kwargs_to_nodes.return_value = (self.project, None)
self.project.add_addon('github', auth=None)
decorated = must_have_addon('github', 'node')(needs_addon_view)
res = decorated()
assert_equal(res, 'openaddon')
@mock.patch('website.project.decorators._kwargs_to_nodes')
def test_must_have_addon_node_false(self, mock_kwargs_to_nodes):
mock_kwargs_to_nodes.return_value = (self.project, None)
decorated = must_have_addon('github', 'node')(needs_addon_view)
with assert_raises(HTTPError):
decorated()
@mock.patch('website.project.decorators.get_current_user')
def test_must_have_addon_user_true(self, mock_current_user):
mock_current_user.return_value = self.project.creator
self.project.creator.add_addon('github')
decorated = must_have_addon('github', 'user')(needs_addon_view)
res = decorated()
assert_equal(res, 'openaddon')
@mock.patch('website.project.decorators.get_current_user')
def test_must_have_addon_user_false(self, mock_current_user):
mock_current_user.return_value = self.project.creator
decorated = must_have_addon('github', 'user')(needs_addon_view)
with assert_raises(HTTPError):
decorated()
示例11: TestFileGuid
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
class TestFileGuid(OsfTestCase):
def setUp(self):
super(OsfTestCase, self).setUp()
self.user = UserFactory()
self.project = ProjectFactory(creator=self.user)
self.project.add_addon('github', auth=Auth(self.user))
self.node_addon = self.project.get_addon('github')
def test_provider(self):
assert_equal('github', GithubGuidFile().provider)
def test_correct_path(self):
guid, _ = self.node_addon.find_or_create_file_guid('perth')
assert_equal(guid.waterbutler_path, 'perth')
assert_equal(guid.waterbutler_path, guid.path)
@mock.patch('website.addons.base.requests.get')
def test_unique_identifier(self, mock_get):
mock_response = mock.Mock(ok=True, status_code=200)
mock_get.return_value = mock_response
mock_response.json.return_value = {
'data': {
'name': 'Morty',
'extra': {
'fileSha': 'Im a little tea pot'
}
}
}
guid, _ = self.node_addon.find_or_create_file_guid('perth')
guid.enrich()
assert_equal(guid.unique_identifier, 'Im a little tea pot')
def test_exception_from_response(self):
mock_response = mock.Mock()
mock_response.json.return_value = {'errors': [{'code': 'too_large'}]}
guid, _ = self.node_addon.find_or_create_file_guid('perth')
with assert_raises(TooBigToRenderError):
guid._exception_from_response(mock_response)
def test_node_addon_get_or_create(self):
guid, created = self.node_addon.find_or_create_file_guid('/4/2')
assert_true(created)
assert_equal(guid.waterbutler_path, '/4/2')
def test_node_addon_get_or_create_finds(self):
guid1, created1 = self.node_addon.find_or_create_file_guid('/foo/bar')
guid2, created2 = self.node_addon.find_or_create_file_guid('/foo/bar')
assert_true(created1)
assert_false(created2)
assert_equals(guid1, guid2)
示例12: test_import_auth_invalid_account
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
def test_import_auth_invalid_account(self):
ea = self.ExternalAccountFactory()
node = ProjectFactory(creator=self.user)
node.add_addon(self.ADDON_SHORT_NAME, auth=self.auth)
node.save()
url = node.api_url_for("{0}_import_auth".format(self.ADDON_SHORT_NAME))
res = self.app.put_json(url, {"external_account_id": ea._id}, auth=self.user.auth, expect_errors=True)
assert_equal(res.status_code, http.FORBIDDEN)
示例13: TestGoogleDriveUtils
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_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)
示例14: TestFileGuid
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
class TestFileGuid(OsfTestCase):
def setUp(self):
super(OsfTestCase, self).setUp()
self.user = UserFactory()
self.project = ProjectFactory(creator=self.user)
self.project.add_addon("github", auth=Auth(self.user))
self.node_addon = self.project.get_addon("github")
def test_provider(self):
assert_equal("github", GithubGuidFile().provider)
def test_correct_path(self):
guid, _ = self.node_addon.find_or_create_file_guid("perth")
assert_equal(guid.waterbutler_path, "perth")
assert_equal(guid.waterbutler_path, guid.path)
def test_extra_without_metadata(self):
guid, _ = self.node_addon.find_or_create_file_guid("perth")
assert_equal(guid.extra, {})
@mock.patch("website.addons.base.requests.get")
def test_unique_identifier(self, mock_get):
mock_response = mock.Mock(ok=True, status_code=200)
mock_get.return_value = mock_response
mock_response.json.return_value = {"data": {"name": "Morty", "extra": {"fileSha": "Im a little tea pot"}}}
guid, _ = self.node_addon.find_or_create_file_guid("perth")
guid.enrich()
assert_equal(guid.unique_identifier, "Im a little tea pot")
def test_exception_from_response(self):
mock_response = mock.Mock()
mock_response.json.return_value = {"errors": [{"code": "too_large"}]}
guid, _ = self.node_addon.find_or_create_file_guid("perth")
with assert_raises(TooBigToRenderError):
guid._exception_from_response(mock_response)
def test_node_addon_get_or_create(self):
guid, created = self.node_addon.find_or_create_file_guid("/4/2")
assert_true(created)
assert_equal(guid.waterbutler_path, "/4/2")
def test_node_addon_get_or_create_finds(self):
guid1, created1 = self.node_addon.find_or_create_file_guid("/foo/bar")
guid2, created2 = self.node_addon.find_or_create_file_guid("/foo/bar")
assert_true(created1)
assert_false(created2)
assert_equals(guid1, guid2)
示例15: test_node_count_deleted_addon
# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import add_addon [as 别名]
def test_node_count_deleted_addon(self):
results = AddonSnapshot().get_events()
github_res = [res for res in results if res['provider']['name'] == 'github'][0]
assert_equal(github_res['nodes']['deleted'], 0)
node = ProjectFactory(creator=self.user)
node.add_addon('github', Auth(self.user))
node_addon = node.get_addon('github')
node_addon.delete()
results = AddonSnapshot().get_events()
github_res = [res for res in results if res['provider']['name'] == 'github'][0]
assert_equal(github_res['nodes']['deleted'], 1)