def test_file_passed_all_validations_most_recent(self): file_ = get_addon_file('valid_webextension.xpi') upload = self.get_upload(abspath=file_, user=self.user, addon=self.addon, version='1.0') newer_upload = self.get_upload(abspath=file_, user=self.user, addon=self.addon, version='0.5') newer_upload.update(created=datetime.today() + timedelta(hours=1)) # The Version is created because the newer upload is for a different # version_string. tasks.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED) self.mocks['parse_addon'].assert_called_with(upload, self.addon, user=self.user) self.mocks['Version.from_upload'].assert_called_with( upload, self.addon, [amo.FIREFOX.id, amo.ANDROID.id], amo.RELEASE_CHANNEL_LISTED, parsed_data=self.mocks['parse_addon'].return_value, )
def create_installable_addon(self): activate('en-US') # using whatever add-on you already have should work imho, otherwise # fall back to a new one for test purposes addon = self.create_featured_addon_with_version_for_install() # the user the add-on gets created with user = UserProfile.objects.get(username='******') user, _ = UserProfile.objects.get_or_create( pk=settings.TASK_USER_ID, defaults={ 'email': '*****@*****.**', 'username': '******' }, ) # Groups should have been created by loaddata initial.json at this # point, we need our user to be part of a group allowed to submit # extensions signed by Mozilla. Let's use Admins (pk=1) as a shortcut. GroupUser.objects.get_or_create(user=user, group=Group.objects.get(pk=1)) # generate a proper uploaded file that simulates what django requires # as request.POST root = os.path.join(settings.ROOT, 'src/olympia/files/fixtures/files') file_to_upload = 'webextension_signed_already.xpi' file_path = os.path.join(root, file_to_upload) # make sure we are not using the file in the source-tree but a # temporary one to avoid the files get moved somewhere else and # deleted from source tree with copy_file_to_temp(file_path) as temporary_path: data = open(temporary_path, 'rb').read() filedata = SimpleUploadedFile( file_to_upload, data, content_type=mimetypes.guess_type(file_to_upload)[0], ) # now, lets upload the file into the system from olympia.devhub.views import handle_upload request = RequestFactory().get('/') request.user = user upload = handle_upload( filedata=filedata, request=request, channel=amo.RELEASE_CHANNEL_LISTED, addon=addon, ) upload.ip_address = '127.0.0.1' # And let's create a new version for that upload. create_version_for_upload(upload.addon, upload, amo.RELEASE_CHANNEL_LISTED) # Change status to public addon.update(status=amo.STATUS_APPROVED)
def test_file_passed_all_validations_not_most_recent(self): file_ = get_addon_file('valid_webextension.xpi') upload = self.get_upload(abspath=file_, user=self.user, addon=self.addon, version='1.0') newer_upload = self.get_upload(abspath=file_, user=self.user, addon=self.addon, version='1.0') newer_upload.update(created=datetime.today() + timedelta(hours=1)) # Check that the older file won't turn into a Version. tasks.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED) assert not self.mocks['Version.from_upload'].called # But the newer one will. tasks.create_version_for_upload(self.addon, newer_upload, amo.RELEASE_CHANNEL_LISTED) self.mocks['Version.from_upload'].assert_called_with( newer_upload, self.addon, [amo.FIREFOX.id, amo.ANDROID.id], amo.RELEASE_CHANNEL_LISTED, parsed_data=self.mocks['parse_addon'].return_value, )
def test_file_passed_all_validations_version_exists(self): upload = self.create_upload() Version.objects.create(addon=upload.addon, version=upload.version) # Check that the older file won't turn into a Version. tasks.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED) assert not self.mocks['Version.from_upload'].called
def test_file_passed_all_validations_most_recent_failed(self): upload = self.create_upload() newer_upload = self.create_upload() newer_upload.update(created=datetime.today() + timedelta(hours=1), valid=False, validation=json.dumps({"errors": 5})) tasks.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED) assert not self.mocks['Version.from_upload'].called
def test_file_passed_all_validations_version_exists(self): file_ = get_addon_file('valid_webextension.xpi') upload = self.get_upload( abspath=file_, user=self.user, addon=self.addon, version='1.0') Version.objects.create(addon=upload.addon, version=upload.version) # Check that the older file won't turn into a Version. tasks.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED) assert not self.mocks['Version.from_upload'].called
def test_file_passed_all_validations_no_version(self): upload = self.create_upload(version=None) tasks.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED) self.mocks['parse_addon'].assert_called_with( upload, self.addon, user=self.user) self.mocks['Version.from_upload'].assert_called_with( upload, self.addon, [amo.FIREFOX.id, amo.ANDROID.id], amo.RELEASE_CHANNEL_LISTED, parsed_data=self.mocks['parse_addon'].return_value)
def test_file_passed_all_validations_beta_string(self): file_ = get_addon_file('valid_webextension.xpi') upload = self.get_upload( abspath=file_, user=self.user, addon=self.addon, version='1.0beta1') tasks.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED) self.mocks['parse_addon'].assert_called_with( upload, self.addon, user=self.user) self.mocks['Version.from_upload'].assert_called_with( upload, self.addon, [amo.FIREFOX.id, amo.ANDROID.id], amo.RELEASE_CHANNEL_LISTED, parsed_data=self.mocks['parse_addon'].return_value)
def test_file_passed_all_validations_most_recent_failed(self): file_ = get_addon_file('valid_webextension.xpi') upload = self.get_upload( abspath=file_, user=self.user, addon=self.addon, version='1.0') newer_upload = self.get_upload( abspath=file_, user=self.user, addon=self.addon, version='1.0') newer_upload.update(created=datetime.today() + timedelta(hours=1), valid=False, validation=json.dumps({"errors": 5})) tasks.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED) assert not self.mocks['Version.from_upload'].called
def create_installable_addon(self): activate('en-US') # using whatever add-on you already have should work imho, otherwise # fall back to a new one for test purposes addon = self.create_featured_addon_with_version_for_install() # the user the add-on gets created with user = UserProfile.objects.get(username='******') user, _ = UserProfile.objects.get_or_create(pk=settings.TASK_USER_ID, defaults={ 'email': '*****@*****.**', 'username': '******' }) # generate a proper uploaded file that simulates what django requires # as request.POST file_to_upload = 'webextension_signed_already.xpi' file_path = get_file(file_to_upload) # make sure we are not using the file in the source-tree but a # temporary one to avoid the files get moved somewhere else and # deleted from source tree with copy_file_to_temp(file_path) as temporary_path: data = open(temporary_path).read() filedata = SimpleUploadedFile( file_to_upload, data, content_type=mimetypes.guess_type(file_to_upload)[0]) # now, lets upload the file into the system from olympia.devhub.views import handle_upload request = RequestFactory().get('/') request.user = user upload = handle_upload( filedata=filedata, request=request, channel=amo.RELEASE_CHANNEL_LISTED, addon=addon, ) # And let's create a new version for that upload. create_version_for_upload(upload.addon, upload, amo.RELEASE_CHANNEL_LISTED) # Change status to public addon.update(status=amo.STATUS_PUBLIC)
def create_installable_addon(self): activate('en-US') # using whatever add-on you already have should work imho, otherwise # fall back to a new one for test purposes addon = self.create_featured_addon_with_version_for_install() # the user the add-on gets created with user = UserProfile.objects.get(username='******') user, _ = UserProfile.objects.get_or_create( pk=settings.TASK_USER_ID, defaults={'email': '*****@*****.**', 'username': '******'}) # generate a proper uploaded file that simulates what django requires # as request.POST file_to_upload = 'webextension_signed_already.xpi' file_path = get_file(file_to_upload) # make sure we are not using the file in the source-tree but a # temporary one to avoid the files get moved somewhere else and # deleted from source tree with copy_file_to_temp(file_path) as temporary_path: data = open(temporary_path).read() filedata = SimpleUploadedFile( file_to_upload, data, content_type=mimetypes.guess_type(file_to_upload)[0]) # now, lets upload the file into the system from olympia.devhub.views import handle_upload request = RequestFactory().get('/') request.user = user upload = handle_upload( filedata=filedata, request=request, channel=amo.RELEASE_CHANNEL_LISTED, addon=addon, ) # And let's create a new version for that upload. create_version_for_upload( upload.addon, upload, amo.RELEASE_CHANNEL_LISTED) # Change status to public addon.update(status=amo.STATUS_PUBLIC)