Beispiel #1
0
    def test_matching_archive(self):
        version = factories.FileVersionFactory(
            location={
                'service': 'cloud',
                settings.WATERBUTLER_RESOURCE: 'osf',
                'object': 'd077f2',
            },
            metadata={'sha256': 'existing'}
        )
        factories.FileVersionFactory(
            location={
                'service': 'cloud',
                settings.WATERBUTLER_RESOURCE: 'osf',
                'object': '06d80e',
            },
            metadata={
                'sha256': 'existing',
                'vault': 'the cloud',
                'archive': 'erchiv'
            }
        )

        assert_is(version._find_matching_archive(), True)
        assert_is_not(version.archive, None)

        assert_equal(version.metadata['vault'], 'the cloud')
        assert_equal(version.metadata['archive'], 'erchiv')
Beispiel #2
0
 def test_ping_not_uploading_raises_error(self):
     version = factories.FileVersionFactory(status=model.status_map['CACHED'])
     with assert_raises(errors.VersionStatusError):
         version.ping(version.signature)
     version = factories.FileVersionFactory(status=model.status_map['COMPLETE'])
     with assert_raises(errors.VersionStatusError):
         version.ping(version.signature)
Beispiel #3
0
 def test_update_metadata_not_found(self):
     self.record.versions = [
         factories.FileVersionFactory(signature='31a64'),
         factories.FileVersionFactory(signature='7aa12'),
     ]
     self.record.save()
     with assert_raises(errors.VersionNotFoundError):
         self.record.update_version_metadata('1143b3', {'archive': 'glacier'})
     assert_not_in('archive', self.record.versions[0].metadata)
     assert_not_in('archive', self.record.versions[1].metadata)
Beispiel #4
0
 def test_update_metadata_found(self):
     self.record.versions = [
         factories.FileVersionFactory(signature='31a64'),
         factories.FileVersionFactory(signature='7aa12'),
     ]
     self.record.save()
     self.record.update_version_metadata('31a64', {'archive': 'glacier'})
     assert_in('archive', self.record.versions[0].metadata)
     assert_equal(self.record.versions[0].metadata['archive'], 'glacier')
     assert_not_in('archive', self.record.versions[1].metadata)
Beispiel #5
0
 def test_is_duplicate_no_location(self):
     version1 = factories.FileVersionFactory(
         status=model.status_map['UPLOADING'],
         location={},
     )
     version2 = factories.FileVersionFactory(
         status=model.status_map['UPLOADING'],
         location={},
     )
     assert_false(version1.is_duplicate(version2))
     assert_false(version2.is_duplicate(version1))
Beispiel #6
0
 def test_is_duplicate_false(self):
     version1 = factories.FileVersionFactory(location={
         'service': 'cloud',
         settings.WATERBUTLER_RESOURCE: 'osf',
         'object': 'd077f2',
     }, )
     version2 = factories.FileVersionFactory(location={
         'service': 'cloud',
         settings.WATERBUTLER_RESOURCE: 'osf',
         'object': '06d80e',
     }, )
     assert_false(version1.is_duplicate(version2))
     assert_false(version2.is_duplicate(version1))
Beispiel #7
0
 def test_update_metadata_found(self):
     self.record.versions = [
         factories.FileVersionFactory(),
         factories.FileVersionFactory(),
     ]
     self.record.versions[0].location['object'] = 'foo'
     self.record.versions[1].location['object'] = 'bar'
     self.record.versions[0].save()
     self.record.versions[1].save()
     self.record.save()
     self.record.update_version_metadata(self.record.versions[0].location,
         {'archive': 'glacier', 'size': 123, 'modified': 'Mon, 16 Feb 2015 18:45:34 GMT'})
     assert_in('archive', self.record.versions[0].metadata)
     assert_equal(self.record.versions[0].metadata['archive'], 'glacier')
     assert_not_in('archive', self.record.versions[1].metadata)
Beispiel #8
0
 def test_touch_pending_many_versions_not_expired(self, mock_time):
     mock_time.return_value = 10
     self.record.versions = [factories.FileVersionFactory() for _ in range(5)]
     self.record.save()
     version = self.record.create_pending_version(self.user, 'c22b59f')
     valid = self.record.touch()
     assert_is(valid, True)
Beispiel #9
0
 def test_resolve_pending_logs_file_update(self):
     nlogs = len(self.project.logs)
     version = factories.FileVersionFactory()
     self.record.versions.append(version)
     self.record.save()
     self.record.create_pending_version(self.user, 'c22b59f')
     self.record.resolve_pending_version(
         'c22b59f',
         {
             'service': 'cloud',
             'container': 'container',
             'object': '7035161',
         },
         {
             'size': 7,
             'content_type': 'text/plain',
             'date_modified': '2014-11-06 22:38',
         },
     )
     self.project.reload()
     assert_equal(len(self.project.logs), nlogs + 1)
     logged = self.project.logs[-1]
     assert_equal(logged.user, self.user)
     assert_equal(
         logged.action,
         'osf_storage_{0}'.format(NodeLog.FILE_UPDATED),
     )
     assert_equal(
         logged.params['urls'],
         logs.build_log_urls(self.project, self.path),
     )
     assert_equal(logged.params['version'], len(self.record.versions))
Beispiel #10
0
 def test_create_pending_bad_signature(self):
     version = factories.FileVersionFactory(
         signature='c22b5f9',
     )
     self.record.versions.append(version)
     with assert_raises(errors.SignatureConsumedError):
         self.record.create_pending_version(self.user, 'c22b5f9')
Beispiel #11
0
 def test_set_cached_not_uploading_raises_error(self):
     version = factories.FileVersionFactory(
         status=model.status_map['CACHED'])
     self.record.versions.append(version)
     self.record.save()
     res = self.send_set_cached_hook(expect_errors=True)
     assert_equal(res.status_code, 400)
Beispiel #12
0
 def test_hgrid_contents(self):
     path = u'kind/of/magíc.mp3'
     model.OsfStorageFileRecord.get_or_create(
         path=path,
         node_settings=self.node_settings,
     )
     version = factories.FileVersionFactory()
     record = model.OsfStorageFileRecord.find_by_path(
         path, self.node_settings)
     record.versions.append(version)
     record.save()
     res = self.app.get(
         self.project.api_url_for(
             'osf_storage_hgrid_contents',
             path='kind/of',
         ),
         auth=self.project.creator.auth,
     )
     assert_equal(len(res.json), 1)
     assert_equal(
         res.json[0],
         utils.serialize_metadata_hgrid(record, self.project, {
             'edit': True,
             'view': True,
         }))
Beispiel #13
0
    def test_after_register_copies_versions(self):
        num_versions = 5
        path = 'jazz/dreamers-ball.mp3'

        record = self.node_settings.root_node.append_file(path)

        for _ in range(num_versions):
            version = factories.FileVersionFactory()
            record.versions.append(version)
        record.save()

        registration = self.project.register_node(
            None,
            self.auth_obj,
            '',
            {},
        )
        assert_true(registration.has_addon('osfstorage'))
        registration_node_settings = registration.get_addon('osfstorage')
        registration_node_settings.reload()
        cloned_record = registration_node_settings.root_node.find_child_by_name(
            path)
        assert_equal(cloned_record.versions, record.versions)
        assert_equal(cloned_record.versions, record.versions)
        assert_true(registration_node_settings.root_node)
Beispiel #14
0
 def test_archived(self):
     version = factories.FileVersionFactory(signature=self.uploadSignature)
     self.record.versions = [version]
     self.record.save()
     self.send_archived_hook()
     version.reload()
     assert_in('archive', version.metadata)
     assert_equal(version.metadata['archive'], 'glacier')
Beispiel #15
0
 def setUp(self):
     super(TestViewFile, self).setUp()
     self.path = 'kind/of/magic.mp3'
     self.record, _ = model.OsfStorageFileRecord.get_or_create(
         self.path, self.node_settings)
     self.version = factories.FileVersionFactory()
     self.record.versions.append(self.version)
     self.record.save()
Beispiel #16
0
 def setUp(self):
     super(TestGetRevisions, self).setUp()
     self.path = 'tie/your/mother/down.mp3'
     self.record = recursively_create_file(self.node_settings, self.path)
     self.record.versions = [
         factories.FileVersionFactory() for __ in range(15)
     ]
     self.record.save()
Beispiel #17
0
 def setUp(self):
     super(TestDownloadFile, self).setUp()
     self.path = u'tie/your/mother/döwn.mp3'
     self.record, _ = model.OsfStorageFileRecord.get_or_create(
         self.path, self.node_settings)
     self.version = factories.FileVersionFactory()
     self.record.versions.append(self.version)
     self.record.save()
Beispiel #18
0
 def test_is_duplicate_has_location_is_not_duplicate(self):
     version1 = factories.FileVersionFactory(
         location={
             'service': 'cloud',
             'container': 'osf',
             'object': 'd077f2',
         },
     )
     version2 = factories.FileVersionFactory(
         location={
             'service': 'cloud',
             'container': 'osf',
             'object': '06d80e',
         },
     )
     assert_false(version1.is_duplicate(version2))
     assert_false(version2.is_duplicate(version1))
Beispiel #19
0
 def setUp(self):
     super(TestGetDownloadUrl, self).setUp()
     self.path = 'frozen/pizza/reviews.gif'
     self.record, _ = model.OsfStorageFileRecord.get_or_create(self.path, self.node_settings)
     for _ in range(3):
         version = factories.FileVersionFactory()
         self.record.versions.append(version)
     self.record.save()
Beispiel #20
0
 def setUp(self):
     super(TestGetRevisions, self).setUp()
     self.path = 'tie/your/mother/down.mp3'
     self.record, _ = model.OsfStorageFileRecord.get_or_create(
         self.path, self.node_settings)
     self.record.versions = [
         factories.FileVersionFactory() for _ in range(15)
     ]
     self.record.save()
Beispiel #21
0
 def test_ping_not_pending(self, mock_time):
     version = factories.FileVersionFactory(last_ping=0)
     self.record.versions.append(version)
     self.record.save()
     mock_time.return_value = 10
     res = self.send_ping_hook(expect_errors=True)
     assert_equal(res.status_code, 400)
     version.reload()
     assert_equal(version.last_ping, 0)
Beispiel #22
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)
     ]
     self.record.versions = self.versions
     self.record.save()
Beispiel #23
0
 def test_archived_version_not_found(self):
     version = factories.FileVersionFactory(
         signature=self.uploadSignature[::-1])
     self.record.versions = [version]
     self.record.save()
     res = self.send_archived_hook(expect_errors=True)
     assert_equal(res.status_code, 400)
     version.reload()
     assert_not_in('archive', version.metadata)
Beispiel #24
0
 def setUp(self):
     super(TestSerializeRevision, self).setUp()
     self.path = 'kind/of/magic.mp3'
     self.record, _ = model.OsfStorageFileRecord.get_or_create(
         self.path, self.node_settings)
     self.versions = [
         factories.FileVersionFactory(creator=self.user) for _ in range(3)
     ]
     self.record.versions = self.versions
     self.record.save()
Beispiel #25
0
 def test_no_matching_archive(self):
     models.FileVersion.remove()
     assert_is(False, factories.FileVersionFactory(
         location={
             'service': 'cloud',
             settings.WATERBUTLER_RESOURCE: 'osf',
             'object': 'd077f2',
         },
         metadata={'sha256': 'existing'}
     )._find_matching_archive())
Beispiel #26
0
 def test_after_fork_copies_stable_records(self):
     path = 'jazz/dreamers-ball.mp3'
     record = model.OsfStorageFileRecord.get_or_create(path, self.node_settings)
     version_pending = factories.FileVersionFactory(status=model.status_map['UPLOADING'])
     record.versions.append(version_pending)
     record.save()
     fork = self.project.fork_node(self.auth_obj)
     fork_node_settings = fork.get_addon('osfstorage')
     cloned_record = model.OsfStorageFileRecord.find_by_path(path, fork_node_settings)
     assert_is(cloned_record, None)
Beispiel #27
0
 def test_view_file_escapes_html_in_name(self, mock_render):
     mock_render.return_value = 'mock'
     path = 'kind/of/<strong>magic.mp3'
     record, _ = model.OsfStorageFileRecord.get_or_create(
         path, self.node_settings)
     version = factories.FileVersionFactory()
     record.versions.append(version)
     record.save()
     res = self.view_file(path).follow(auth=self.project.creator.auth)
     assert record.name in res
Beispiel #28
0
 def test_update_metadata(self):
     version = factories.FileVersionFactory()
     version.update_metadata({
         'archive': 'glacier',
         'size': 123,
         'modified': 'Mon, 16 Feb 2015 18:45:34 GMT'
     })
     version.reload()
     assert_in('archive', version.metadata)
     assert_equal(version.metadata['archive'], 'glacier')
Beispiel #29
0
 def test_fields(self):
     version = factories.FileVersionFactory(
         size=1024,
         content_type='application/json',
         date_modified=datetime.datetime.now(),
     )
     retrieved = model.OsfStorageFileVersion.load(version._id)
     assert_true(retrieved.creator)
     assert_true(retrieved.location)
     assert_true(retrieved.size)
     assert_true(retrieved.content_type)
     assert_true(retrieved.date_modified)
Beispiel #30
0
 def setUp(self):
     super(TestUpdateMetadataHook, self).setUp()
     self.path = 'greasy/pízza.png'
     self.record = recursively_create_file(self.node_settings, self.path)
     self.version = factories.FileVersionFactory()
     self.record.versions = [self.version]
     self.record.save()
     self.payload = {
         'metadata': {'archive': 'glacier', 'size': 123, 'modified': 'Mon, 16 Feb 2015 18:45:34 GMT'},
         'version': self.version._id,
         'size': 123,
     }