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


Python models.OsfStorageFileNode类代码示例

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


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

示例1: test_delete_file_no_guid

    def test_delete_file_no_guid(self):
        child = self.node_settings.get_root().append_file('Test')

        assert_is(OsfStorageFileNode.load(child._id).guids.first(), None)

        with mock.patch('osf.models.files.apps.get_model') as get_model:
            child.delete()

            assert_is(get_model.called, False)

        assert_is(OsfStorageFileNode.load(child._id), None)
开发者ID:erinspace,项目名称:osf.io,代码行数:11,代码来源:test_models.py

示例2: test_delete_file_guids

    def test_delete_file_guids(self):
        child = self.node_settings.get_root().append_file('Test')
        guid = child.get_guid(create=True)

        assert_is_not(OsfStorageFileNode.load(child._id).guids.first(), None)

        with mock.patch('osf.models.files.apps.get_model') as get_model:
            child.delete()

            assert_is(get_model.called, True)
            assert_is(get_model('osf.Comment').objects.filter.called, True)

        assert_is(OsfStorageFileNode.load(child._id), None)
开发者ID:erinspace,项目名称:osf.io,代码行数:13,代码来源:test_models.py

示例3: 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

示例4: checkin_files_by_user

def checkin_files_by_user(node, user):
    ''' Listens to a contributor being removed to check in all of their files
    '''
    from addons.osfstorage.models import OsfStorageFileNode
    files = OsfStorageFileNode.find(Q('node', 'eq', node) & Q('checkout', 'eq', user))
    for file in files:
        file.checkout = None
        file.save()
开发者ID:adlius,项目名称:osf.io,代码行数:8,代码来源:listeners.py

示例5: test_get_file_guids_for_live_file

    def test_get_file_guids_for_live_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

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

示例6: test_get_file_guids_for_live_folder_wo_guids

    def test_get_file_guids_for_live_folder_wo_guids(self):
        node = self.node_settings.owner
        folder = OsfStorageFolder(name='foofolder', node=node)
        folder.save()

        files = []
        for i in range(1, 4):
            files.append(folder.append_file('foo.{}'.format(i)))

        all_guids = OsfStorageFileNode.get_file_guids(
            '/' + folder._id, provider='osfstorage', node=node)
        assert [] == all_guids
开发者ID:adlius,项目名称:osf.io,代码行数:12,代码来源:test_models.py

示例7: test_delete

    def test_delete(self):
        file = self.root_node.append_file('Newfile')

        resp = self.delete(file)

        assert_equal(resp.status_code, 200)
        assert_equal(resp.json, {'status': 'success'})
        fid = file._id
        del file
        # models.StoredFileNode._clear_object_cache()
        assert_is(OsfStorageFileNode.load(fid), None)
        assert_true(models.TrashedFileNode.load(fid))
开发者ID:geeksnglitter,项目名称:osf.io,代码行数:12,代码来源:test_views.py

示例8: test_delete_folder

    def test_delete_folder(self):
        parent = self.node_settings.get_root().append_folder('Test')
        kids = []
        for x in range(10):
            kid = parent.append_file(str(x))
            kid.save()
            kids.append(kid)
        count = OsfStorageFileNode.find().count()
        tcount = models.TrashedFileNode.find().count()

        parent.delete()

        assert_is(OsfStorageFileNode.load(parent._id), None)
        assert_equals(count - 11, OsfStorageFileNode.find().count())
        assert_equals(tcount + 11, models.TrashedFileNode.find().count())

        for kid in kids:
            assert_is(
                OsfStorageFileNode.load(kid._id),
                None
            )
开发者ID:adlius,项目名称:osf.io,代码行数:21,代码来源:test_models.py

示例9: wrapped

        def wrapped(*args, **kwargs):
            if 'fid' not in kwargs and default_root:
                file_node = OsfStorageFolder.objects.get_root(kwargs['target'])
            else:
                file_node = OsfStorageFileNode.get(kwargs.get('fid'), kwargs['target'])
            if must_be and file_node.kind != must_be:
                raise HTTPError(httplib.BAD_REQUEST, data={
                    'message_short': 'incorrect type',
                    'message_long': 'FileNode must be of type {} not {}'.format(must_be, file_node.kind)
                })

            kwargs['file_node'] = file_node

            return func(*args, **kwargs)
开发者ID:CenterForOpenScience,项目名称:osf.io,代码行数:14,代码来源:decorators.py

示例10: test_create_with_parent

    def test_create_with_parent(self):
        resp = self.create_folder('name')

        assert_equal(resp.status_code, 201)
        assert_equal(self.root_node.children.count(), 1)
        assert_equal(self.root_node.children.all()[0].serialize(), resp.json['data'])

        resp = self.create_folder('name', parent=OsfStorageFileNode.load(resp.json['data']['id']))

        assert_equal(resp.status_code, 201)
        assert_equal(self.root_node.children.count(), 1)
        assert_false(self.root_node.children.all()[0].is_file)
        assert_equal(self.root_node.children.all()[0].children.count(), 1)
        assert_false(self.root_node.children.all()[0].children.all()[0].is_file)
        assert_equal(self.root_node.children.all()[0].children.all()[0].serialize(), resp.json['data'])
开发者ID:geeksnglitter,项目名称:osf.io,代码行数:15,代码来源:test_views.py

示例11: test_get_file_guids_for_live_folder

    def test_get_file_guids_for_live_folder(self):
        node = self.node_settings.owner
        folder = OsfStorageFolder(name='foofolder', node=node)
        folder.save()

        files = []
        for i in range(1, 4):
            files.append(folder.append_file('foo.{}'.format(i)))
            files[-1].get_guid(create=True)

        guids = [file.get_guid()._id for file in files]
        assert len(guids) == len(files)

        all_guids = OsfStorageFileNode.get_file_guids(
            '/' + folder._id, provider='osfstorage', node=node)
        assert sorted(guids) == sorted(all_guids)
开发者ID:adlius,项目名称:osf.io,代码行数:16,代码来源:test_models.py

示例12: wrapped

    def wrapped(payload, *args, **kwargs):
        try:
            user = OSFUser.load(payload['user'])
            dest_node = AbstractNode.load(payload['destination']['node'])
            source = OsfStorageFileNode.get(payload['source'], kwargs['node'])
            dest_parent = OsfStorageFolder.get(payload['destination']['parent'], dest_node)

            kwargs.update({
                'user': user,
                'source': source,
                'destination': dest_parent,
                'name': payload['destination']['name'],
            })
        except KeyError:
            raise HTTPError(httplib.BAD_REQUEST)

        return func(*args, **kwargs)
开发者ID:geeksnglitter,项目名称:osf.io,代码行数:17,代码来源:decorators.py

示例13: test_get_file_guids_for_trashed_folder_recursive_wo_guids

    def test_get_file_guids_for_trashed_folder_recursive_wo_guids(self):
        node = self.node_settings.owner
        folder = OsfStorageFolder(name='foofolder', target=node)
        folder.save()

        files = []
        for i in range(1, 4):
            files.append(folder.append_file('foo.{}'.format(i)))

        subfolder = folder.append_folder('subfoo')
        for i in range(1, 4):
            files.append(subfolder.append_file('subfoo.{}'.format(i)))

        folder.delete()

        all_guids = OsfStorageFileNode.get_file_guids(
            '/' + folder._id, provider='osfstorage', target=node)
        assert [] == all_guids
开发者ID:erinspace,项目名称:osf.io,代码行数:18,代码来源:test_models.py

示例14: test_delete_file

    def test_delete_file(self):
        child = self.node_settings.get_root().append_file('Test')
        field_names = [f.name for f in child._meta.get_fields() if not f.is_relation and f.name not in ['id', 'content_type_pk']]
        child_data = {f: getattr(child, f) for f in field_names}
        child.delete()

        assert_is(OsfStorageFileNode.load(child._id), None)
        trashed = models.TrashedFileNode.load(child._id)
        child_storage = dict()
        trashed_storage = dict()
        trashed_storage['parent'] = trashed.parent._id
        child_storage['materialized_path'] = child.materialized_path
        assert_equal(trashed.path, '/' + child._id)
        trashed_field_names = [f.name for f in child._meta.get_fields() if not f.is_relation and
                               f.name not in ['id', '_materialized_path', 'content_type_pk', '_path', 'deleted_on', 'deleted_by', 'type']]
        for f, value in child_data.iteritems():
            if f in trashed_field_names:
                assert_equal(getattr(trashed, f), value)
开发者ID:adlius,项目名称:osf.io,代码行数:18,代码来源:test_models.py

示例15: post

    def post(self, request, *args, **kwargs):
        serializer = self.serializer_class(data=request.data, context=self.get_serializer_context())
        if serializer.is_valid():
            source = serializer.validated_data.pop('source')
            destination = serializer.validated_data.pop('destination')
            name = destination.get('name')
            dest_target = self.get_target(target_id=destination.get('target'))
            try:
                source = OsfStorageFileNode.get(source, self.get_object())
            except OsfStorageFileNode.DoesNotExist:
                raise NotFound

            try:
                dest_parent = OsfStorageFolder.get(destination.get('parent'), dest_target)
            except OsfStorageFolder.DoesNotExist:
                raise NotFound
            serializer.save(source=source, destination=dest_parent, name=name)
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:erinspace,项目名称:osf.io,代码行数:19,代码来源:views.py


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