def test_current_not_valid_raises(self): mod = 'olympia.files.utils.SafeZip.initialize_and_validate' with mock.patch(mod) as is_valid: is_valid.return_value = False with tempfile.NamedTemporaryFile(suffix='.xpi') as destination: with self.assertRaises(ValidationError): build_webext_dictionary_from_legacy( self.addon, destination)
def migrate_legacy_dictionary_to_webextension(addon): """Migrate a single legacy dictionary to webextension format, creating a new package from the current_version, faking an upload to create a new Version instance.""" user = UserProfile.objects.get(pk=settings.TASK_USER_ID) now = datetime.now() # Wrap zip in FileUpload for Version.from_upload() to consume. upload = FileUpload.objects.create( user=user, valid=True) destination = os.path.join( user_media_path('addons'), 'temp', uuid.uuid4().hex + '.xpi') target_language = build_webext_dictionary_from_legacy(addon, destination) if not addon.target_locale: addon.update(target_locale=target_language) upload.update(path=destination) parsed_data = parse_addon(upload, addon=addon, user=user) # Create version. # WebExtension dictionaries are only compatible with Firefox Desktop # Firefox for Android uses the OS spellchecking. version = Version.from_upload( upload, addon, selected_apps=[amo.FIREFOX.id], channel=amo.RELEASE_CHANNEL_LISTED, parsed_data=parsed_data) activity.log_create(amo.LOG.ADD_VERSION, version, addon, user=user) # Sign the file, and set it to public. That should automatically set # current_version to the version we created. file_ = version.all_files[0] sign_file(file_) file_.update(datestatuschanged=now, reviewed=now, status=amo.STATUS_PUBLIC)
def test_addon_has_no_target_locale(self): self.addon.update(target_locale=None) with tempfile.NamedTemporaryFile(suffix='.xpi') as destination: build_webext_dictionary_from_legacy(self.addon, destination) self.check_xpi_file_contents(destination, '1.0.1webext') self.addon.reload()
def test_basic(self): with tempfile.NamedTemporaryFile(suffix='.xpi') as destination: build_webext_dictionary_from_legacy(self.addon, destination) self.check_xpi_file_contents(destination, '1.0.1webext')
def test_version_number_typefix(self): self.addon.current_version.update(version='1.1-typefix') with tempfile.NamedTemporaryFile(suffix='.xpi') as destination: build_webext_dictionary_from_legacy(self.addon, destination) self.check_xpi_file_contents(destination, '1.2webext')
def test_invalid_dictionary_path_raises(self): self.xpi_copy_over( self.addon.current_version.all_files[0], 'extension.xpi') with tempfile.NamedTemporaryFile(suffix='.xpi') as destination: with self.assertRaises(ValidationError): build_webext_dictionary_from_legacy(self.addon, destination)
def test_invalid_dictionary_path_raises(self): self.xpi_copy_over(self.addon.current_version.all_files[0], 'extension.xpi') with tempfile.NamedTemporaryFile(suffix='.xpi') as destination: with self.assertRaises(ValidationError): build_webext_dictionary_from_legacy(self.addon, destination)
def test_addon_has_no_target_locale(self): self.addon.update(target_locale=None) with tempfile.NamedTemporaryFile(suffix='.xpi') as destination: with self.assertRaises(ValidationError): build_webext_dictionary_from_legacy(self.addon, destination)