def test_upload_new_version_existing_version_number_is_higher(self): extension = Extension.objects.create() ExtensionVersion.objects.create(extension=extension, version='0.2') upload = self.upload('extension') with self.assertRaises(ParseError): # Try to upload version 0.1 it should fail since 0.2 is the latest. ExtensionVersion.from_upload(upload, parent=extension)
def test_upload_new_version_existing_version(self): extension = Extension.objects.create() ExtensionVersion.objects.create(extension=extension, version='0.1') ExtensionVersion.objects.create(extension=extension, version='0.2.0') upload = self.upload('extension') # Also uses version "0.1". with self.assertRaises(ParseError): ExtensionVersion.from_upload(upload, parent=extension)
def test_remove_signed_file_not_exists(self, public_storage_mock): extension = Extension(pk=42, slug='mocked_ext') version = ExtensionVersion(extension=extension, pk=123) public_storage_mock.exists.return_value = False version.remove_signed_file() eq_(public_storage_mock.exists.call_args[0][0], version.signed_file_path) eq_(public_storage_mock.delete.call_count, 0)
def test_sign_and_move_file_error(self, remove_signed_file_mock, private_storage_mock, sign_app_mock): extension = Extension(uuid='12345678123456781234567812345678') version = ExtensionVersion(extension=extension, pk=123) sign_app_mock.side_effect = SigningError with self.assertRaises(SigningError): version.sign_and_move_file() eq_(remove_signed_file_mock.call_count, 1)
def test_remove_signed_file(self, mocked_public_storage): extension = Extension(pk=42, slug='mocked_ext') version = ExtensionVersion(extension=extension, pk=123) mocked_public_storage.exists.return_value = True version.remove_signed_file() eq_(mocked_public_storage.exists.call_args[0][0], version.signed_file_path) eq_(mocked_public_storage.delete.call_args[0][0], version.signed_file_path)
def test_sign_and_move_file(self, remove_signed_file_mock, private_storage_mock, sign_app_mock): extension = Extension(uuid='ab345678123456781234567812345678') version = ExtensionVersion(extension=extension, pk=123) version.sign_and_move_file() expected_args = ( private_storage_mock.open.return_value, version.signed_file_path, json.dumps({ 'id': 'ab345678123456781234567812345678', 'version': 123, }) ) eq_(sign_app_mock.call_args[0], expected_args) eq_(remove_signed_file_mock.call_count, 0)
def fake_object(self, data): """Create a fake instance of Extension from ES data.""" obj = Extension(id=data['id']) data['created'] = es_to_datetime(data['created']) data['last_updated'] = es_to_datetime(data['last_updated']) data['modified'] = es_to_datetime(data['modified']) # Create a fake ExtensionVersion for latest_public_version. if data['latest_public_version']: obj.latest_public_version = ExtensionVersion( extension=obj, id=data['latest_public_version']['id'], created=es_to_datetime( data['latest_public_version']['created']), size=data['latest_public_version'].get('size', 0), status=STATUS_PUBLIC, version=data['latest_public_version']['version'], ) # Set basic attributes we'll need on the fake instance using the data # from ES. self._attach_fields( obj, data, ('author', 'created', 'default_language', 'icon_hash', 'last_updated', 'modified', 'slug', 'status', 'version')) obj.deleted = data['is_deleted'] obj.disabled = data['is_disabled'] obj.uuid = data['guid'] # Attach translations for all translated attributes. # obj.default_language should be set first for this to work. self._attach_translations(obj, data, ( 'name', 'description', )) # Some methods might need the raw data from ES, put it on obj. obj.es_data = data return obj
def test_upload_new_version_existing_pending_are_rendered_obsolete(self): extension = Extension.objects.create() older_version = ExtensionVersion.objects.create( extension=extension, version='0.0.0', status=STATUS_PENDING) old_version = ExtensionVersion.objects.create( extension=extension, version='0.0', status=STATUS_PENDING) eq_(extension.latest_version, old_version) eq_(extension.status, STATUS_PENDING) upload = self.upload('extension') # Instead of calling Extension.from_upload(), we need to call # ExtensionVersion.from_upload() directly, since an Extension already # exists. version = ExtensionVersion.from_upload(upload, parent=extension) eq_(extension.latest_version, version) eq_(extension.status, STATUS_PENDING) eq_(version.status, STATUS_PENDING) old_version.reload() older_version.reload() eq_(old_version.status, STATUS_OBSOLETE) eq_(older_version.status, STATUS_OBSOLETE)
def test_upload_new_version(self): extension = Extension.objects.create() old_version = ExtensionVersion.objects.create( extension=extension, version='0.0') eq_(extension.latest_version, old_version) eq_(extension.status, STATUS_NULL) upload = self.upload('extension') # Instead of calling Extension.from_upload(), we need to call # ExtensionVersion.from_upload() directly, since an Extension already # exists. version = ExtensionVersion.from_upload(upload, parent=extension) eq_(extension.latest_version, version) eq_(extension.status, STATUS_PENDING) eq_(version.version, '0.1') eq_(version.default_language, 'en-GB') eq_(version.filename, 'extension-%s.zip' % version.version) ok_(version.filename in version.file_path) ok_(private_storage.exists(version.file_path)) eq_(version.manifest, self.expected_manifest) eq_(version.status, STATUS_PENDING)
def test_sign_and_move_file_no_version_pk(self, private_storage_mock, sign_app_mock): extension = Extension(uuid='12345678123456781234567812345678') version = ExtensionVersion(extension=extension) with self.assertRaises(SigningError): version.sign_and_move_file()
def test_upload_new_version_no_parent(self): upload = self.upload('extension') with self.assertRaises(ValueError): ExtensionVersion.from_upload(upload)