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


Python ProjectFactory.get_addon方法代码示例

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


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

示例1: TestMustBeAddonAuthorizerDecorator

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_addon [as 别名]
class TestMustBeAddonAuthorizerDecorator(AuthAppTestCase):

    def setUp(self):
        super(TestMustBeAddonAuthorizerDecorator, self).setUp()
        self.project = ProjectFactory()
        self.decorated = must_be_addon_authorizer('github')(needs_addon_view)

    @mock.patch('website.project.decorators._kwargs_to_nodes')
    @mock.patch('framework.auth.decorators.Auth.from_kwargs')
    def test_must_be_authorizer_true(self, mock_get_current_user, mock_kwargs_to_nodes):

        # Mock
        mock_get_current_user.return_value = Auth(self.project.creator)
        mock_kwargs_to_nodes.return_value = (None, self.project)

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

        # Test
        res = self.decorated()
        assert_equal(res, 'openaddon')

    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()

    def test_must_be_authorizer_no_user_settings(self):
        self.project.add_addon('github', auth=None)
        with assert_raises(HTTPError):
            self.decorated()

    def test_must_be_authorizer_no_node_settings(self):
        with assert_raises(HTTPError):
            self.decorated()
开发者ID:cslzchen,项目名称:osf.io,代码行数:52,代码来源:test_auth.py

示例2: test_move_file_out_of_node

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_addon [as 别名]
    def test_move_file_out_of_node(self):
        folder = self.root_node.append_folder('A long time ago')
        file = folder.append_file('in a galaxy')
        # project having a preprint should not block other moves
        preprint_file = self.root_node.append_file('far')
        self.node.preprint_file = preprint_file
        self.node.save()

        project = ProjectFactory(creator=self.user)
        project_settings = project.get_addon('osfstorage')
        project_root_node = project_settings.get_root()

        folder_two = project_root_node.append_folder('far away')
        res = self.send_hook(
            'osfstorage_move_hook',
            {'nid': self.root_node.node._id},
            payload={
                'source': folder._id,
                'node': self.root_node._id,
                'user': self.user._id,
                'destination': {
                    'parent': folder_two._id,
                    'node': folder_two.node._id,
                    'name': folder_two.name,
                }
            },
            method='post_json',
            expect_errors=True,
        )
        assert_equal(res.status_code, 200)
开发者ID:adlius,项目名称:osf.io,代码行数:32,代码来源:test_views.py

示例3: test_migration

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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)')
开发者ID:545zhou,项目名称:osf.io,代码行数:34,代码来源:test_box_connect_external_accounts.py

示例4: TestGoogleDriveHgridViews

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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')
开发者ID:KerryKDiehl,项目名称:osf.io,代码行数:37,代码来源:test_views.py

示例5: TestNodeSettings

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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)
开发者ID:XTech2K,项目名称:osf.io,代码行数:37,代码来源:test_model.py

示例6: test_move_preprint_file_out_of_node

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_addon [as 别名]
    def test_move_preprint_file_out_of_node(self):
        folder = self.root_node.append_folder('From Here')
        file = folder.append_file('No I don\'t wanna go')
        self.node.preprint_file = file
        self.node.save()

        project = ProjectFactory(creator=self.user)
        project_settings = project.get_addon('osfstorage')
        project_root_node = project_settings.get_root()

        folder_two = project_root_node.append_folder('To There')
        res = self.send_hook(
            'osfstorage_move_hook',
            {'nid': self.root_node.node._id},
            payload={
                'source': folder._id,
                'node': self.root_node._id,
                'user': self.user._id,
                'destination': {
                    'parent': folder_two._id,
                    'node': folder_two.node._id,
                    'name': folder_two.name,
                }
            },
            method='post_json',
            expect_errors=True,
        )
        assert_equal(res.status_code, 403)
开发者ID:adlius,项目名称:osf.io,代码行数:30,代码来源:test_views.py

示例7: TestNodeSettings

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_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)
开发者ID:rmoorman,项目名称:osf.io,代码行数:36,代码来源:test_models.py

示例8: TestDatasetMigration

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_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)
开发者ID:adlius,项目名称:osf.io,代码行数:37,代码来源:test_dataverse_migrate_study.py

示例9: test_oauth_callback_with_node

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_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)
开发者ID:lbanner,项目名称:osf.io,代码行数:33,代码来源:test_views.py

示例10: TestCreateBucket

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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"}')
开发者ID:KerryKDiehl,项目名称:osf.io,代码行数:62,代码来源:test_view.py

示例11: TestAssertion

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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)
开发者ID:545zhou,项目名称:osf.io,代码行数:31,代码来源:test_models.py

示例12: TestHookMigration

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_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)
开发者ID:adlius,项目名称:osf.io,代码行数:36,代码来源:update_hooks.py

示例13: TestViewsAuth

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_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
开发者ID:GageGaskins,项目名称:osf.io,代码行数:36,代码来源:test_views.py

示例14: TestFileGuid

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import get_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)
开发者ID:lbanner,项目名称:osf.io,代码行数:60,代码来源:test_models.py

示例15: TestGoogleDriveUtils

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory 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)
开发者ID:KerryKDiehl,项目名称:osf.io,代码行数:59,代码来源:test_views.py


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