Ejemplo n.º 1
0
 def setUp(self):
     super(TestSerializeRevision, self).setUp()
     self.path = 'kind-of-magic.webm'
     self.record = self.node_settings.get_root().append_file(self.path)
     self.versions = [
         factories.FileVersionFactory(creator=self.user) for __ in range(3)
     ]
     attach_versions(self.record, self.versions)
     self.record.save()
Ejemplo n.º 2
0
def manually_archive(tree, reg, node_settings, parent=None):
    if not isinstance(tree, list):
        tree = [tree]
    for filenode in tree:
        if filenode['deleted']:
            continue
        if filenode.get('parent') and (
            (parent is not None
             and filenode['parent']._id != parent.copied_from._id) or
            (parent is None and filenode['parent'].name != '')):
            # Not the parent we're looking for
            continue
        file_obj = filenode['object']
        cloned = file_obj.clone()
        if cloned.is_deleted:
            if cloned.is_file:
                cloned.recast(OsfStorageFile._typedmodels_type)
            else:
                cloned.recast(OsfStorageFolder._typedmodels_type)
        if not parent:
            parent = reg.get_addon('osfstorage').get_root()
            cloned.name = node_settings.archive_folder_name
        else:
            cloned.name = filenode['name']
        cloned.parent = parent
        cloned.target = reg
        cloned.copied_from = file_obj
        try:
            cloned.save()
        except IntegrityError:
            # Files sometimes already created
            cloned = reg.files.get(name=cloned.name)

        if file_obj.versions.exists(
        ) and filenode['version']:  # Min version identifier is 1
            if not cloned.versions.filter(
                    identifier=filenode['version']).exists():
                attach_versions(
                    cloned,
                    file_obj.versions.filter(
                        identifier__lte=filenode['version']), file_obj)

        if filenode.get('children'):
            manually_archive(filenode['children'],
                             reg,
                             node_settings,
                             parent=cloned)
Ejemplo n.º 3
0
    def test_get_version(self):
        v1 = models.FileVersion(identifier='1')
        v2 = models.FileVersion(identifier='2')
        v1.save()
        v2.save()

        file = TestFile(
            _path='afile',
            name='name',
            target=self.node,
            provider='test',
            materialized_path='/long/path/to/name',
        )
        file.save()

        attach_versions(file, [v1, v2])

        assert_equals(file.get_version('1'), v1)
        assert_equals(file.get_version('2', required=True), v2)

        assert_is(file.get_version('3'), None)

        with assert_raises(exceptions.VersionNotFoundError):
            file.get_version('3', required=True)