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 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)