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


Python models.OsfStorageFile类代码示例

本文整理汇总了Python中addons.osfstorage.models.OsfStorageFile的典型用法代码示例。如果您正苦于以下问题:Python OsfStorageFile类的具体用法?Python OsfStorageFile怎么用?Python OsfStorageFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_get_file_guids_trashed_file_wo_guid

 def test_get_file_guids_trashed_file_wo_guid(self):
     node = self.node_settings.owner
     file = OsfStorageFile(name='foo', node=node)
     file.save()
     file.delete()
     assert [] == OsfStorageFileNode.get_file_guids(
         '/' + file._id, provider='osfstorage', node=node)
开发者ID:adlius,项目名称:osf.io,代码行数:7,代码来源:test_models.py

示例2: setUp

    def setUp(self):
        super(TestSetPreprintFile, self).setUp()

        self.user = AuthUserFactory()
        self.auth = Auth(user=self.user)
        self.read_write_user = AuthUserFactory()
        self.read_write_user_auth = Auth(user=self.read_write_user)

        self.project = ProjectFactory(creator=self.user)
        self.file = OsfStorageFile.create(
            node=self.project,
            path='/panda.txt',
            name='panda.txt',
            materialized_path='/panda.txt')
        self.file.save()

        self.file_two = OsfStorageFile.create(
            node=self.project,
            path='/pandapanda.txt',
            name='pandapanda.txt',
            materialized_path='/pandapanda.txt')
        self.file_two.save()

        self.project.add_contributor(self.read_write_user, permissions=[permissions.WRITE])
        self.project.save()

        self.preprint = PreprintFactory(project=self.project, finish=False)
开发者ID:adlius,项目名称:osf.io,代码行数:27,代码来源:test_preprints.py

示例3: test_not_just_primary_file_returned

    def test_not_just_primary_file_returned(self):
        filename = 'my second file'
        second_file = OsfStorageFile.create(
            target_object_id=self.preprint.id,
            target_content_type=ContentType.objects.get_for_model(self.preprint),
            path='/{}'.format(filename),
            name=filename,
            materialized_path='/{}'.format(filename))

        second_file.save()
        from addons.osfstorage import settings as osfstorage_settings

        second_file.create_version(self.user, {
            'object': '06d80e',
            'service': 'cloud',
            osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
        }, {
            'size': 1337,
            'contentType': 'img/png'
        }).save()
        second_file.parent = self.preprint.root_folder
        second_file.save()

        assert len(self.preprint.files.all()) == 2
        res = self.app.get(self.url, auth=self.user.auth)
        assert res.status_code == 200

        data = res.json['data']
        assert len(data) == 2
        assert data[0]['id'] == self.preprint.primary_file._id
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:30,代码来源:test_preprint_files_list.py

示例4: addon_view_or_download_quickfile

def addon_view_or_download_quickfile(**kwargs):
    fid = kwargs.get('fid', 'NOT_AN_FID')
    file_ = OsfStorageFile.load(fid)
    if not file_:
        raise HTTPError(httplib.NOT_FOUND, data={
            'message_short': 'File Not Found',
            'message_long': 'The requested file could not be found.'
        })
    return proxy_url('/project/{}/files/osfstorage/{}/'.format(file_.target._id, fid))
开发者ID:aaxelb,项目名称:osf.io,代码行数:9,代码来源:views.py

示例5: test_file_download_url_no_guid

 def test_file_download_url_no_guid(self):
     file_ = self.root.append_file('Timber.mp3')
     path = OsfStorageFile.find_one( Q('node', 'eq', file_.node_id)).path
     deep_url = '/' + file_.node._id + '/files/osfstorage' + path + '/'
     find = query_file('Timber.mp3')['results']
     assert_not_equal(file_.path, '')
     assert_equal(file_.path, path)
     assert_equal(find[0]['guid_url'], None)
     assert_equal(find[0]['deep_url'], deep_url)
开发者ID:adlius,项目名称:osf.io,代码行数:9,代码来源:test_elastic_search.py

示例6: test_get_file_guids_for_trashed_file

    def test_get_file_guids_for_trashed_file(self):
        node = self.node_settings.owner
        file = OsfStorageFile(name='foo', node=node)
        file.save()

        file.get_guid(create=True)
        guid = file.get_guid()._id

        file.delete()
        assert guid is not None
        assert guid in OsfStorageFileNode.get_file_guids(
            '/' + file._id, provider='osfstorage', node=node)
开发者ID:adlius,项目名称:osf.io,代码行数:12,代码来源:test_models.py

示例7: test_redirects

    def test_redirects(self, app, project, user):
        # test_redirect_to_node_view
        url = '/{}guids/{}/'.format(API_BASE, project._id)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}nodes/{}/'.format(
            API_DOMAIN, API_BASE, project._id)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_to_registration_view
        registration = RegistrationFactory()
        url = '/{}guids/{}/'.format(API_BASE, registration._id)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}registrations/{}/'.format(
            API_DOMAIN, API_BASE, registration._id)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_to_collections_view
        collection = CollectionFactory()
        url = '/{}guids/{}/'.format(API_BASE, collection._id)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}collections/{}/'.format(
            API_DOMAIN, API_BASE, collection._id)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_to_file_view
        test_file = OsfStorageFile.create(
            node=ProjectFactory(),
            path='/test', name='test',
            materialized_path='/test',
        )
        test_file.save()
        guid = test_file.get_guid(create=True)
        url = '/{}guids/{}/'.format(API_BASE, guid._id)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}files/{}/'.format(
            API_DOMAIN, API_BASE, test_file._id)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_to_comment_view
        comment = CommentFactory()
        url = '/{}guids/{}/'.format(API_BASE, comment._id)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}comments/{}/'.format(
            API_DOMAIN, API_BASE, comment._id)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_throws_404_for_invalid_guids
        url = '/{}guids/{}/'.format(API_BASE, 'fakeguid')
        res = app.get(url, auth=user.auth, expect_errors=True)
        assert res.status_code == 404
开发者ID:leb2dg,项目名称:osf.io,代码行数:55,代码来源:test_guid_detail.py

示例8: _create

    def _create(cls, target_class, *args, **kwargs):
        update_task_patcher = mock.patch('website.preprints.tasks.on_preprint_updated.si')
        update_task_patcher.start()

        finish = kwargs.pop('finish', True)
        set_doi = kwargs.pop('set_doi', True)
        is_published = kwargs.pop('is_published', True)
        instance = cls._build(target_class, *args, **kwargs)

        doi = kwargs.pop('doi', None)
        license_details = kwargs.pop('license_details', None)
        filename = kwargs.pop('filename', None) or 'preprint_file.txt'
        subjects = kwargs.pop('subjects', None) or [[SubjectFactory()._id]]
        instance.article_doi = doi

        instance.machine_state = kwargs.pop('machine_state', 'initial')
        user = kwargs.pop('creator', None) or instance.creator
        instance.save()

        preprint_file = OsfStorageFile.create(
            target_object_id=instance.id,
            target_content_type=ContentType.objects.get_for_model(instance),
            path='/{}'.format(filename),
            name=filename,
            materialized_path='/{}'.format(filename))

        preprint_file.save()
        from addons.osfstorage import settings as osfstorage_settings

        preprint_file.create_version(user, {
            'object': '06d80e',
            'service': 'cloud',
            osfstorage_settings.WATERBUTLER_RESOURCE: 'osf',
        }, {
            'size': 1337,
            'contentType': 'img/png'
        }).save()
        update_task_patcher.stop()
        if finish:
            auth = Auth(user)

            instance.set_primary_file(preprint_file, auth=auth, save=True)
            instance.set_subjects(subjects, auth=auth)
            if license_details:
                instance.set_preprint_license(license_details, auth=auth)
            instance.set_published(is_published, auth=auth)
            create_task_patcher = mock.patch('website.identifiers.utils.request_identifiers')
            mock_create_identifier = create_task_patcher.start()
            if is_published and set_doi:
                mock_create_identifier.side_effect = sync_set_identifiers(instance)
            create_task_patcher.stop()

        instance.save()
        return instance
开发者ID:aaxelb,项目名称:osf.io,代码行数:54,代码来源:factories.py

示例9: test_redirect_to_file_view

 def test_redirect_to_file_view(self):
     test_file = OsfStorageFile.create(
         node=ProjectFactory(),
         path='/test',
         name='test',
         materialized_path='/test',
     )
     test_file.save()
     guid = test_file.get_guid(create=True)
     url = '/{}guids/{}/'.format(API_BASE, guid._id)
     res = self.app.get(url, auth=self.user.auth)
     redirect_url = '{}{}files/{}/'.format(API_DOMAIN, API_BASE, test_file._id)
     assert_equal(res.status_code, 302)
     assert_equal(res.location, redirect_url)
开发者ID:adlius,项目名称:osf.io,代码行数:14,代码来源:test_guid_detail.py

示例10: test_admin_can_set_file

    def test_admin_can_set_file(self):
        initial_file = self.preprint.primary_file
        file = OsfStorageFile.create(
            node=self.project,
            path='/panda.txt',
            name='panda.txt',
            materialized_path='/panda.txt')
        file.save()

        self.preprint.set_primary_file(file, auth=Auth(self.user), save=True)

        self.preprint.reload()
        self.preprint.node.reload()
        assert_not_equal(initial_file._id, self.preprint.primary_file._id)
        assert_equal(file._id, self.preprint.primary_file._id)
开发者ID:adlius,项目名称:osf.io,代码行数:15,代码来源:test_preprints.py

示例11: test_nonadmin_cannot_set_file

    def test_nonadmin_cannot_set_file(self):
        initial_file = self.preprint.primary_file
        file = OsfStorageFile.create(
            node=self.project,
            path='/panda.txt',
            name='panda.txt',
            materialized_path='/panda.txt')
        file.save()

        with assert_raises(PermissionsError):
            self.preprint.set_primary_file(file, auth=Auth(self.write_contrib), save=True)

        self.preprint.reload()
        self.preprint.node.reload()
        assert_equal(initial_file._id, self.preprint.primary_file._id)
开发者ID:adlius,项目名称:osf.io,代码行数:15,代码来源:test_preprints.py

示例12: test_redirect_when_viewing_private_project_file_through_view_only_link

    def test_redirect_when_viewing_private_project_file_through_view_only_link(self):
        project = ProjectFactory()
        test_file = OsfStorageFile.create(
            node=project,
            path='/test',
            name='test',
            materialized_path='/test',
        )
        test_file.save()
        guid = test_file.get_guid(create=True)
        view_only_link = self._add_private_link(project)

        url = '/{}guids/{}/?view_only={}'.format(API_BASE, guid._id, view_only_link.key)
        res = self.app.get(url, auth=AuthUserFactory().auth)
        redirect_url = '{}{}files/{}/?view_only={}'.format(API_DOMAIN, API_BASE, test_file._id, view_only_link.key)
        assert_equal(res.status_code, 302)
        assert_equal(res.location, redirect_url)
开发者ID:adlius,项目名称:osf.io,代码行数:17,代码来源:test_guid_detail.py

示例13: _create

    def _create(cls, target_class, project=None, is_public=True, filename='preprint_file.txt', provider=None, 
                doi=None, external_url=None, is_published=True, subjects=None, finish=True, *args, **kwargs):
        save_kwargs(**kwargs)
        user = None
        if project:
            user = project.creator
        user = kwargs.get('user') or kwargs.get('creator') or user or UserFactory()
        kwargs['creator'] = user
        # Original project to be converted to a preprint
        project = project or AbstractNodeFactory(*args, **kwargs)
        if user._id not in project.permissions:
            project.add_contributor(
                contributor=user,
                permissions=permissions.CREATOR_PERMISSIONS,
                log=False,
                save=False
            )
        project.save()
        project.reload()

        file = OsfStorageFile.create(
            node=project,
            path='/{}'.format(filename),
            name=filename,
            materialized_path='/{}'.format(filename))
        file.save()

        preprint = target_class(node=project, provider=provider)

        auth = Auth(project.creator)

        if finish:
            preprint.set_primary_file(file, auth=auth)
            subjects = subjects or [[SubjectFactory()._id]]
            preprint.set_subjects(subjects, auth=auth)
            preprint.set_published(is_published, auth=auth)
        
        if not preprint.is_published:
            project._has_abandoned_preprint = True

        project.preprint_article_doi = doi
        project.save()
        preprint.save()

        return preprint
开发者ID:adlius,项目名称:osf.io,代码行数:45,代码来源:factories.py

示例14: test_redirects_through_view_only_link

    def test_redirects_through_view_only_link(self, app, project, user):

        # test_redirect_when_viewing_private_project_through_view_only_link
        view_only_link = PrivateLinkFactory(anonymous=False)
        view_only_link.nodes.add(project)
        view_only_link.save()

        url = '/{}guids/{}/?view_only={}'.format(
            API_BASE, project._id, view_only_link.key)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}nodes/{}/?view_only={}'.format(
            API_DOMAIN, API_BASE, project._id, view_only_link.key)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_when_viewing_private_project_file_through_view_only_link
        test_file = OsfStorageFile.create(
            node=project,
            path='/test',
            name='test',
            materialized_path='/test',
        )
        test_file.save()
        guid = test_file.get_guid(create=True)
        url = '/{}guids/{}/?view_only={}'.format(
            API_BASE, guid._id, view_only_link.key)
        res = app.get(url, auth=user.auth)
        redirect_url = '{}{}files/{}/?view_only={}'.format(
            API_DOMAIN, API_BASE, test_file._id, view_only_link.key)
        assert res.status_code == 302
        assert res.location == redirect_url

        # test_redirect_when_viewing_private_project_comment_through_view_only_link
        comment = CommentFactory(node=project)
        url = '/{}guids/{}/?view_only={}'.format(
            API_BASE, comment._id, view_only_link.key)
        res = app.get(url, auth=AuthUserFactory().auth)
        redirect_url = '{}{}comments/{}/?view_only={}'.format(
            API_DOMAIN, API_BASE, comment._id, view_only_link.key)
        assert res.status_code == 302
        assert res.location == redirect_url
开发者ID:leb2dg,项目名称:osf.io,代码行数:41,代码来源:test_guid_detail.py

示例15: test_serialize

    def test_serialize(self):
        file = OsfStorageFile(name='MOAR PYLONS', node=self.node_settings.owner)
        file.save()

        assert_equals(file.serialize(), {
            u'id': file._id,
            u'path': file.path,
            u'created': None,
            u'name': u'MOAR PYLONS',
            u'kind': 'file',
            u'version': 0,
            u'downloads': 0,
            u'size': None,
            u'modified': None,
            u'contentType': None,
            u'checkout': None,
            u'md5': None,
            u'sha256': None,
        })

        version = file.create_version(
            self.user,
            {
                u'service': u'cloud',
                settings.WATERBUTLER_RESOURCE: u'osf',
                u'object': u'06d80e',
            }, {
                u'size': 1234,
                u'contentType': u'text/plain'
            })

        assert_equals(file.serialize(), {
            u'id': file._id,
            u'path': file.path,
            u'created': version.date_created.isoformat(),
            u'name': u'MOAR PYLONS',
            u'kind': u'file',
            u'version': 1,
            u'downloads': 0,
            u'size': 1234L,
            u'modified': version.date_created.isoformat(),
            u'contentType': u'text/plain',
            u'checkout': None,
            u'md5': None,
            u'sha256': None,
        })
开发者ID:adlius,项目名称:osf.io,代码行数:46,代码来源:test_models.py


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