Beispiel #1
0
 def test_ping_bad_signature(self):
     version = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['UPLOADING'],
         signature='c22b5f9',
     )
     with assert_raises(errors.SignatureMismatchError):
         version.ping(version.signature[::-1])
Beispiel #2
0
 def test_expired_pending_active(self, mock_time):
     mock_time.return_value = 0
     version = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['UPLOADING'],
         signature='c22b5f9',
         last_ping=0,
     )
     assert_false(version.expired)
Beispiel #3
0
 def test_expired_pending_inactive(self, mock_time):
     version = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['UPLOADING'],
         signature='c22b5f9',
         last_ping=0,
     )
     mock_time.return_value = settings.PING_TIMEOUT + 1
     assert_true(version.expired)
Beispiel #4
0
 def test_create_pending_path_locked(self):
     version = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['UPLOADING'],
         date_created=datetime.datetime.utcnow(),
     )
     version.save()
     self.record.versions.append(version)
     with assert_raises(errors.PathLockedError):
         self.record.create_pending_version(self.user, 'c22b5f9')
Beispiel #5
0
 def test_ping_uploading(self, mock_time):
     mock_time.return_value = 10
     version = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['UPLOADING'],
         signature='c22b5f9',
     )
     assert_equal(version.last_ping, mock_time.return_value)
     mock_time.return_value = 20
     version.ping(version.signature)
     assert_equal(version.last_ping, mock_time.return_value)
Beispiel #6
0
 def test_finish_bad_signature(self):
     version = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['UPLOADING'],
         date_created=datetime.datetime.utcnow(),
         signature='c22b5f9',
     )
     version.save()
     with assert_raises(errors.SignatureMismatchError):
         version.resolve(
             '78c9a53',
             factories.generic_location,
             {},
         )
Beispiel #7
0
 def test_resolve_complete_raises_error(self, mock_datetime):
     mock_datetime.now.return_value = self.mock_date
     mock_datetime.utcnow.return_value = self.mock_date
     version = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['COMPLETE'],
         date_created=datetime.datetime.utcnow(),
         signature='c22b5f9',
     )
     metadata = {
         'size': 1024,
         'content_type': 'text/plain',
         'date_modified': self.mock_date.isoformat(),
         'md5': '3f92d3',
     }
     with assert_raises(errors.VersionStatusError):
         version.resolve('c22b5f9', factories.generic_location, metadata)
Beispiel #8
0
 def test_after_register_copies_stable_records(self):
     path = 'jazz/dreamers-ball.mp3'
     record = model.OsfStorageFileRecord.get_or_create(path, self.node_settings)
     version_pending = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['UPLOADING'],
     )
     version_pending.save()
     record.versions.append(version_pending)
     record.save()
     registration = self.project.register_node(
         None,
         self.auth_obj,
         '',
         {},
     )
     registration_node_settings = registration.get_addon('osfstorage')
     cloned_record = model.OsfStorageFileRecord.find_by_path(path, registration_node_settings)
     assert_is(cloned_record, None)
Beispiel #9
0
 def test_resolve_cached(self, mock_datetime):
     mock_datetime.now.return_value = self.mock_date
     mock_datetime.utcnow.return_value = self.mock_date
     version = model.OsfStorageFileVersion(
         creator=self.user,
         status=model.status_map['CACHED'],
         date_created=datetime.datetime.utcnow(),
         signature='c22b5f9',
     )
     metadata = {
         'size': 1024,
         'content_type': 'text/plain',
         'date_modified': self.mock_date.isoformat(),
         'md5': '3f92d3',
     }
     version.resolve('c22b5f9', factories.generic_location, metadata)
     assert_equal(version.date_resolved, self.mock_date)
     assert_equal(version.status, model.status_map['COMPLETE'])
     assert_equal(version.size, 1024)
     assert_equal(version.content_type, 'text/plain')
     assert_equal(version.date_modified, self.mock_date)
     assert_equal(version.metadata, metadata)