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


Python ProjectFactory.delete_addon方法代码示例

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


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

示例1: test_wiki_deleted_shows_as_deleted

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_addon [as 别名]
    def test_wiki_deleted_shows_as_deleted(self):
        node = ProjectFactory(creator=self.user)
        node.delete_addon('wiki', auth=Auth(self.user))

        results = AddonSnapshot().get_events()
        wiki_res = [res for res in results if res['provider']['name'] == 'wiki'][0]

        assert_equal(wiki_res['nodes']['deleted'], 1)
开发者ID:adlius,项目名称:osf.io,代码行数:10,代码来源:test_addon_snapshot.py

示例2: TestMustHaveAddonDecorator

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_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 = (None, self.project)
        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 = (None, self.project)
        self.project.delete_addon('github', auth=None)
        decorated = must_have_addon('github', 'node')(needs_addon_view)
        with assert_raises(HTTPError):
            decorated()

    @mock.patch('framework.auth.decorators.Auth.from_kwargs')
    def test_must_have_addon_user_true(self, mock_current_user):
        mock_current_user.return_value = Auth(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('framework.auth.decorators.Auth.from_kwargs')
    def test_must_have_addon_user_false(self, mock_current_user):
        mock_current_user.return_value = Auth(self.project.creator)
        self.project.creator.delete_addon('github')
        decorated = must_have_addon('github', 'user')(needs_addon_view)
        with assert_raises(HTTPError):
            decorated()
开发者ID:erinmayhood,项目名称:osf.io,代码行数:39,代码来源:test_auth.py

示例3: TestAddonFileViews

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_addon [as 别名]

#.........这里部分代码省略.........
    def test_no_action_calls_view_file(self, mock_view_file):
        self.user.reload()
        self.project.reload()

        path = 'cloudfiles'
        mock_view_file.return_value = self.get_mako_return()
        guid, _ = self.node_addon.find_or_create_file_guid('/' + path)

        self.app.get(guid.guid_url, auth=self.user.auth)

        args, kwargs = mock_view_file.call_args
        assert_equals(kwargs, {})
        assert_equals(args[-1], {})
        assert_equals(args[1], self.project)
        assert_equals(args[0].user, self.user)
        assert_equals(args[2], self.node_addon)

    def test_download_create_guid(self):
        path = 'cloudfiles'

        self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth
        )

        guid, created = self.node_addon.find_or_create_file_guid('/' + path)

        assert_true(guid)
        assert_false(created)
        assert_equals(guid.waterbutler_path, '/' + path)

    def test_unauthorized_addons_raise(self):
        path = 'cloudfiles'
        self.node_addon.user_settings = None
        self.node_addon.save()

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 401)

    def test_head_returns_url(self):
        path = 'the little engine that couldnt'
        guid, _ = self.node_addon.find_or_create_file_guid('/' + path)

        download_url = furl.furl(guid.download_url)
        download_url.args['accept_url'] = 'false'

        resp = self.app.head(guid.guid_url, auth=self.user.auth)

        assert_urls_equal(resp.headers['Location'], download_url.url)

    def test_nonexistent_addons_raise(self):
        path = 'cloudfiles'
        self.project.delete_addon('github', Auth(self.user))
        self.project.save()

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 400)

    def test_unauth_addons_raise(self):
        path = 'cloudfiles'
        self.node_addon.user_settings = None
        self.node_addon.save()

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 401)
开发者ID:ticklemepierce,项目名称:osf.io,代码行数:104,代码来源:test_addons.py

示例4: TestFileGuid

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_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('dropbox', auth=Auth(self.user))
        self.node_addon = self.project.get_addon('dropbox')
        self.node_addon.folder = '/baz'
        self.node_addon.save()

    def test_provider(self):
        assert_equal('dropbox', DropboxFile().provider)

    def test_correct_path(self):
        guid = DropboxFile(node=self.project, path='baz/foo/bar')

        assert_equals(guid.path, 'baz/foo/bar')
        assert_equals(guid.waterbutler_path, '/foo/bar')

    def test_path_doesnt_crash_without_addon(self):
        guid = DropboxFile(node=self.project, path='baz/foo/bar')
        self.project.delete_addon('dropbox', Auth(self.user))

        assert_is(self.project.get_addon('dropbox'), None)

        assert_true(guid.path)
        assert_true(guid.waterbutler_path)

    def test_path_doesnt_crash_nonconfig_addon(self):
        guid = DropboxFile(node=self.project, path='baz/foo/bar')
        self.node_addon.folder = None
        self.node_addon.save()
        self.node_addon.reload()

        assert_true(guid.path)
        assert_true(guid.waterbutler_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': {
                    'revisionId': 'Ricksy'
                }
            }
        }

        guid = DropboxFile(node=self.project, path='/foo/bar')

        guid.enrich()
        assert_equals('Ricksy', guid.unique_identifier)

    def test_node_addon_get_or_create(self):
        guid, created = self.node_addon.find_or_create_file_guid('/foo/bar')

        assert_true(created)
        assert_equal(guid.path, 'baz/foo/bar')
        assert_equal(guid.waterbutler_path, '/foo/bar')

    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)

    def test_node_addon_get_or_create_finds_changed(self):
        guid1, created1 = self.node_addon.find_or_create_file_guid('/foo/bar')

        self.node_addon.folder = '/baz/foo'
        self.node_addon.save()
        self.node_addon.reload()
        guid2, created2 = self.node_addon.find_or_create_file_guid('/bar')

        assert_true(created1)
        assert_false(created2)
        assert_equals(guid1, guid2)
开发者ID:hmoco,项目名称:osf.io,代码行数:83,代码来源:test_models.py

示例5: TestAddonFileViews

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_addon [as 别名]

#.........这里部分代码省略.........

    def test_download_create_guid(self):
        file_node = self.get_test_file()
        assert_is(file_node.get_guid(), None)

        self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=file_node.path.strip('/'),
                provider='github',
            ),
            auth=self.user.auth
        )

        assert_true(file_node.get_guid())

    def test_unauthorized_addons_raise(self):
        path = 'cloudfiles'
        self.node_addon.user_settings = None
        self.node_addon.save()

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 401)

    def test_nonstorage_addons_raise(self):
        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path='sillywiki',
                provider='wiki',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 400)

    def test_head_returns_url(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.head('/{}/'.format(guid._id), auth=self.user.auth)
        location = furl.furl(resp.location)
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(direct=None, version=None))

    def test_head_returns_url_with_version(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.head('/{}/?revision=1&foo=bar'.format(guid._id), auth=self.user.auth)
        location = furl.furl(resp.location)
        # Note: version is added but us but all other url params are added as well
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(direct=None, revision=1, version=1, foo='bar'))

    def test_nonexistent_addons_raise(self):
        path = 'cloudfiles'
        self.project.delete_addon('github', Auth(self.user))
        self.project.save()

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 400)

    def test_unauth_addons_raise(self):
        path = 'cloudfiles'
        self.node_addon.user_settings = None
        self.node_addon.save()

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 401)
开发者ID:mattspitzer,项目名称:osf.io,代码行数:104,代码来源:test_addons.py

示例6: TestFileGuid

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

    def setUp(self):
        super(OsfTestCase, self).setUp()
        self.user = AuthUserFactory()
        self.project = ProjectFactory(creator=self.user)
        self.project.add_addon('figshare', auth=Auth(self.user))
        self.node_addon = self.project.get_addon('figshare')
        self.node_addon.figshare_id = 8
        self.node_addon.figshare_type = 'project'
        self.node_addon.save()

    def test_provider(self):
        assert_equal(
            'figshare',
            model.FigShareGuidFile().provider
        )

    def test_path_doesnt_crash_without_addon(self):
        guid = model.FigShareGuidFile(node=self.project, path='/baz/foo/bar')
        self.project.delete_addon('figshare', Auth(self.user))

        assert_is(self.project.get_addon('figshare'), None)

        assert_true(guid.path)
        assert_true(guid.waterbutler_path)

    def test_path_doesnt_crash_nonconfig_addon(self):
        guid = model.FigShareGuidFile(node=self.project, path='/baz/foo/bar')
        self.node_addon.figshare_type = None
        self.node_addon.figshare_id = None
        self.node_addon.save()
        self.node_addon.reload()

        assert_true(guid.path)
        assert_true(guid.waterbutler_path)

    def test_correct_path_article(self):
        guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project)
        guid._metadata_cache = {'name': 'shigfare.io'}
        tpath = guid.mfr_temp_path
        cpath = guid.mfr_cache_path

        assert_not_equal(tpath, cpath)

    def test_mfr_test_path(self):
        self.node_addon.figshare_type = 'fileset'
        self.node_addon.save()
        self.node_addon.reload()

        guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project)
        assert_equal(guid.waterbutler_path, '/2')

    def test_correct_path_project(self):
        guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project)
        assert_equal(guid.waterbutler_path, '/4/2')

    def test_unique_identifier(self):
        guid = model.FigShareGuidFile(file_id=2, article_id=4)
        assert_equal(guid.unique_identifier, '42')

    def test_exception_from_response(self):
        mock_response = mock.Mock()
        mock_response.json.return_value = {
            'data': {
                'name': 'Morty',
                'extra': {
                    'status': 'drafts'
                }
            }
        }
        guid = model.FigShareGuidFile(file_id=2, article_id=4)

        with assert_raises(exceptions.FigshareIsDraftError):
            guid._exception_from_response(mock_response)

        assert_equal(guid.name, 'Morty')

    @mock.patch('website.addons.base.requests.get')
    def test_enrich_raises(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': {
                    'status': 'drafts'
                }
            }
        }

        guid = model.FigShareGuidFile(file_id=2, article_id=4, node=self.project)

        with assert_raises(exceptions.FigshareIsDraftError):
            guid.enrich()

        assert_equal(guid.name, 'Morty')

    @mock.patch('website.addons.base.requests.get')
    def test_enrich_works(self, mock_get):
#.........这里部分代码省略.........
开发者ID:PatrickEGorman,项目名称:osf.io,代码行数:103,代码来源:test_models.py

示例7: TestMigrateFiles

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

    def setUp(self):
        super(TestMigrateFiles, self).setUp()
        self.project = ProjectFactory()
        self.user = self.project.creator
        self.auth_obj = Auth(user=self.user)
        self.project.delete_addon('osfstorage', auth=None, _force=True)
        for idx in range(5):
            content = 'i want {0} pizzas'.format(idx)
            self.project.add_file(
                auth=self.auth_obj,
                file_name='pizza.md',
                content=content,
                size=len(content),
                content_type='text/markdown',
            )

    def check_record(self, record):
        assert_true(record)
        assert_equal(len(record.versions), 5)
        for idx, version in enumerate(record.versions):
            assert_false(version.pending)
            expected = 'i want {0} pizzas'.format(idx)
            download_url = utils.get_waterbutler_download_url(idx + 1, version, record)
            resp = requests.get(download_url)
            assert_equal(expected, resp.content)

    def test_migrate(self):
        main(dry_run=False)
        node_settings = self.project.get_addon('osfstorage')
        assert_true(node_settings)
        record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
        self.check_record(record)
        # Test idempotence of migration
        main(dry_run=False)
        assert_equal(len(record.versions), 5)

    def test_migrate_incomplete(self):
        node_settings = self.project.get_or_add_addon('osfstorage', auth=None, log=False)
        record = model.OsfStorageFileRecord.get_or_create('pizza.md', node_settings)
        node_file = NodeFile.load(self.project.files_versions['pizza_md'][0])
        content, _ = self.project.read_file_object(node_file)
        file_pointer = StringIO(content)
        hash_str = scripts_settings.UPLOAD_PRIMARY_HASH(content).hexdigest()
        record.create_pending_version(node_file.uploader, hash_str)
        main(dry_run=False)

    def test_migrate_fork(self):
        fork = self.project.fork_node(auth=self.auth_obj)
        main(dry_run=False)
        node_settings = self.project.get_addon('osfstorage')
        record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
        self.check_record(record)
        fork_node_settings = fork.get_addon('osfstorage')
        fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
        self.check_record(fork_record)

    def test_migrate_corrupt_fork_repo_deleted(self):
        fork = self.project.fork_node(auth=self.auth_obj)
        fork_repo = os.path.join(settings.UPLOADS_PATH, fork._id)
        shutil.rmtree(fork_repo)
        main(dry_run=False)
        node_settings = self.project.get_addon('osfstorage')
        record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
        self.check_record(record)
        fork_node_settings = fork.get_addon('osfstorage')
        fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
        self.check_record(fork_record)

    def test_migrate_corrupt_fork_git_dir_deleted(self):
        fork = self.project.fork_node(auth=self.auth_obj)
        fork_git_dir = os.path.join(settings.UPLOADS_PATH, fork._id, '.git')
        shutil.rmtree(fork_git_dir)
        main(dry_run=False)
        node_settings = self.project.get_addon('osfstorage')
        record = model.OsfStorageFileRecord.find_by_path('pizza.md', node_settings)
        self.check_record(record)
        fork_node_settings = fork.get_addon('osfstorage')
        fork_record = model.OsfStorageFileRecord.find_by_path('pizza.md', fork_node_settings)
        self.check_record(fork_record)
开发者ID:adlius,项目名称:osf.io,代码行数:83,代码来源:migrate_files.py

示例8: TestNodeLogList

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_addon [as 别名]
class TestNodeLogList(ApiTestCase):
    def setUp(self):
        super(TestNodeLogList, self).setUp()
        self.user = AuthUserFactory()
        self.contrib = AuthUserFactory()
        self.creator = AuthUserFactory()
        self.user_auth = Auth(self.user)
        self.NodeLogFactory = ProjectFactory()
        self.pointer = ProjectFactory()

        self.private_project = ProjectFactory(is_public=False, creator=self.user)
        self.private_url = '/{}nodes/{}/logs/'.format(API_BASE, self.private_project._id)

        self.public_project = ProjectFactory(is_public=True, creator=self.user)
        self.public_url = '/{}nodes/{}/logs/'.format(API_BASE, self.public_project._id)

    def tearDown(self):
        super(TestNodeLogList, self).tearDown()
        NodeLog.remove()

    def test_add_tag(self):
        user_auth = Auth(self.user)
        self.public_project.add_tag("Jeff Spies", auth=user_auth)
        assert_equal("tag_added", self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'tag_added')
        assert_equal("Jeff Spies", self.public_project.logs[OSF_LATEST].params['tag'])

    def test_remove_tag(self):
        user_auth = Auth(self.user)
        self.public_project.add_tag("Jeff Spies", auth=user_auth)
        assert_equal("tag_added", self.public_project.logs[OSF_LATEST].action)
        self.public_project.remove_tag("Jeff Spies", auth=self.user_auth)
        assert_equal("tag_removed", self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'tag_removed')
        assert_equal("Jeff Spies", self.public_project.logs[OSF_LATEST].params['tag'])

    def test_project_created(self):
        res = self.app.get(self.public_url)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(self.public_project.logs[OSF_FIRST].action, "project_created")
        assert_equal(self.public_project.logs[OSF_FIRST].action,res.json['data'][API_LATEST]['attributes']['action'])

    def test_log_create_on_public_project(self):
        res = self.app.get(self.public_url)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_datetime_equal(parse_date(res.json['data'][API_FIRST]['attributes']['date']),
                              self.public_project.logs[OSF_FIRST].date)
        assert_equal(res.json['data'][API_FIRST]['attributes']['action'], self.public_project.logs[OSF_FIRST].action)

    def test_log_create_on_private_project(self):
        res = self.app.get(self.private_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_datetime_equal(datetime.datetime.strptime(res.json['data'][API_FIRST]['attributes']['date'], "%Y-%m-%dT%H:%M:%S.%f"),
                              self.private_project.logs[OSF_FIRST].date)
        assert_equal(res.json['data'][API_FIRST]['attributes']['action'], self.private_project.logs[OSF_FIRST].action)

    def test_add_addon(self):
        self.public_project.add_addon('github', auth=self.user_auth)
        assert_equal('addon_added', self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'addon_added')

    def test_project_add_remove_contributor(self):
        self.public_project.add_contributor(self.contrib, auth=self.user_auth)
        assert_equal('contributor_added', self.public_project.logs[OSF_LATEST].action)
        self.public_project.remove_contributor(self.contrib, auth=self.user_auth)
        assert_equal('contributor_removed', self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'contributor_removed')
        assert_equal(res.json['data'][1]['attributes']['action'], 'contributor_added')

    def test_remove_addon(self):
        self.public_project.add_addon('github', auth=self.user_auth)
        assert_equal('addon_added', self.public_project.logs[OSF_LATEST].action)
        self.public_project.delete_addon('github', auth=self.user_auth)
        assert_equal('addon_removed', self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
        assert_equal(res.json['data'][API_LATEST]['attributes']['action'], 'addon_removed')

    def test_add_pointer(self):
        self.public_project.add_pointer(self.pointer, auth=Auth(self.user), save=True)
        assert_equal('pointer_created', self.public_project.logs[OSF_LATEST].action)
        res = self.app.get(self.public_url, auth=self.user.auth)
        assert_equal(res.status_code, 200)
        assert_equal(len(res.json['data']), len(self.public_project.logs))
#.........这里部分代码省略.........
开发者ID:HalcyonChimera,项目名称:osf.io,代码行数:103,代码来源:test_node_logs.py

示例9: TestAddonFileViews

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_addon [as 别名]

#.........这里部分代码省略.........
    def test_nonstorage_addons_raise(self):
        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path='sillywiki',
                provider='wiki',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 400)

    def test_head_returns_url(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.head('/{}/'.format(guid._id), auth=self.user.auth)
        location = furl.furl(resp.location)
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(direct=None, version=None))

    def test_head_returns_url_with_version(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.head('/{}/?revision=1&foo=bar'.format(guid._id), auth=self.user.auth)
        location = furl.furl(resp.location)
        # Note: version is added but us but all other url params are added as well
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(direct=None, revision=1, version=None, foo='bar'))

    def test_nonexistent_addons_raise(self):
        path = 'cloudfiles'
        self.project.delete_addon('github', Auth(self.user))
        self.project.save()

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 400)

    def test_unauth_addons_raise(self):
        path = 'cloudfiles'
        self.node_addon.user_settings = None
        self.node_addon.save()

        resp = self.app.get(
            self.project.web_url_for(
                'addon_view_or_download_file',
                path=path,
                provider='github',
                action='download'
            ),
            auth=self.user.auth,
            expect_errors=True
        )

        assert_equals(resp.status_code, 401)
开发者ID:baylee-d,项目名称:osf.io,代码行数:70,代码来源:test_addons.py

示例10: TestAddonFileViews

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_addon [as 别名]

#.........这里部分代码省略.........

    def test_nonstorage_addons_raise(self):
        resp = self.app.get(
            self.project.web_url_for(
                "addon_view_or_download_file", path="sillywiki", provider="wiki", action="download"
            ),
            auth=self.user.auth,
            expect_errors=True,
        )

        assert_equals(resp.status_code, 400)

    def test_head_returns_url(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.head("/{}/".format(guid._id), auth=self.user.auth)
        location = furl.furl(resp.location)
        assert_urls_equal(location.url, file_node.generate_waterbutler_url(direct=None, version=None))

    def test_head_returns_url_with_version(self):
        file_node = self.get_test_file()
        guid = file_node.get_guid(create=True)

        resp = self.app.head("/{}/?revision=1&foo=bar".format(guid._id), auth=self.user.auth)
        location = furl.furl(resp.location)
        # Note: version is added but us but all other url params are added as well
        assert_urls_equal(
            location.url, file_node.generate_waterbutler_url(direct=None, revision=1, version=None, foo="bar")
        )

    def test_nonexistent_addons_raise(self):
        path = "cloudfiles"
        self.project.delete_addon("github", Auth(self.user))
        self.project.save()

        resp = self.app.get(
            self.project.web_url_for("addon_view_or_download_file", path=path, provider="github", action="download"),
            auth=self.user.auth,
            expect_errors=True,
        )

        assert_equals(resp.status_code, 400)

    def test_unauth_addons_raise(self):
        path = "cloudfiles"
        self.node_addon.user_settings = None
        self.node_addon.save()

        resp = self.app.get(
            self.project.web_url_for("addon_view_or_download_file", path=path, provider="github", action="download"),
            auth=self.user.auth,
            expect_errors=True,
        )

        assert_equals(resp.status_code, 401)

    def test_delete_action_creates_trashed_file_node(self):
        file_node = self.get_test_file()
        payload = {"provider": file_node.provider, "metadata": {"path": "/test/Test", "materialized": "/test/Test"}}
        views.addon_delete_file_node(
            self=None, node=self.project, user=self.user, event_type="file_removed", payload=payload
        )
        assert_false(StoredFileNode.load(file_node._id))
        assert_true(TrashedFileNode.load(file_node._id))
开发者ID:ycchen1989,项目名称:osf.io,代码行数:69,代码来源:test_addons.py

示例11: TestFileGuid

# 需要导入模块: from tests.factories import ProjectFactory [as 别名]
# 或者: from tests.factories.ProjectFactory import delete_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("dropbox", auth=Auth(self.user))
        self.node_addon = self.project.get_addon("dropbox")
        self.node_addon.folder = "/baz"
        self.node_addon.save()

    def test_provider(self):
        assert_equal("dropbox", DropboxFile().provider)

    def test_correct_path(self):
        guid = DropboxFile(node=self.project, path="baz/foo/bar")

        assert_equals(guid.path, "baz/foo/bar")
        assert_equals(guid.waterbutler_path, "/foo/bar")

    def test_path_doesnt_crash_without_addon(self):
        guid = DropboxFile(node=self.project, path="baz/foo/bar")
        self.project.delete_addon("dropbox", Auth(self.user))

        assert_is(self.project.get_addon("dropbox"), None)

        assert_true(guid.path)
        assert_true(guid.waterbutler_path)

    def test_path_doesnt_crash_nonconfig_addon(self):
        guid = DropboxFile(node=self.project, path="baz/foo/bar")
        self.node_addon.folder = None
        self.node_addon.save()
        self.node_addon.reload()

        assert_true(guid.path)
        assert_true(guid.waterbutler_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": {"revisionId": "Ricksy"}}}

        guid = DropboxFile(node=self.project, path="/foo/bar")

        guid.enrich()
        assert_equals("Ricksy", guid.unique_identifier)

    def test_node_addon_get_or_create(self):
        guid, created = self.node_addon.find_or_create_file_guid("/foo/bar")

        assert_true(created)
        assert_equal(guid.path, "baz/foo/bar")
        assert_equal(guid.waterbutler_path, "/foo/bar")

    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)

    def test_node_addon_get_or_create_finds_changed(self):
        guid1, created1 = self.node_addon.find_or_create_file_guid("/foo/bar")

        self.node_addon.folder = "/baz/foo"
        self.node_addon.save()
        self.node_addon.reload()
        guid2, created2 = self.node_addon.find_or_create_file_guid("/bar")

        assert_true(created1)
        assert_false(created2)
        assert_equals(guid1, guid2)
开发者ID:jinluyuan,项目名称:osf.io,代码行数:76,代码来源:test_models.py


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