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.
        utils.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED)
        assert not self.mocks['Version.from_upload'].called

        # But the newer one will.
        utils.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.RELEASE_CHANNEL_LISTED,
            selected_apps=[amo.FIREFOX.id, amo.ANDROID.id],
            parsed_data=self.mocks['parse_addon'].return_value,
        )
Exemple #2
0
    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': '******'},
        )
        if not user.last_login_ip:
            user.update(last_login_ip='127.0.0.1')
        # 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_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.
        utils.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED)
        assert not self.mocks['Version.from_upload'].called
Exemple #4
0
def submit_file(addon_pk, upload_pk, channel):
    from olympia.devhub.utils import create_version_for_upload

    addon = Addon.unfiltered.get(pk=addon_pk)
    upload = FileUpload.objects.get(pk=upload_pk)
    if upload.passed_all_validations:
        create_version_for_upload(addon, upload, channel)
    else:
        log.info('Skipping version creation for {upload_uuid} that failed '
                 'validation'.format(upload_uuid=upload.uuid))
 def test_statsd_logging_new_version(self):
     file_ = get_addon_file('valid_webextension.xpi')
     upload = self.get_upload(
         abspath=file_, user=self.user, addon=self.addon, version=None
     )
     parsed_data = mock.Mock()
     utils.create_version_for_upload(
         self.addon, upload, amo.RELEASE_CHANNEL_LISTED, parsed_data=parsed_data
     )
     assert self.mocks['parse_addon'].call_count == 0
     self.mocks['Version.from_upload'].assert_called()
     self.mocks['statsd.incr'].assert_any_call('signing.submission.version.listed')
 def test_file_passed_all_validations_no_version(self):
     file_ = get_addon_file('valid_webextension.xpi')
     upload = self.get_upload(
         abspath=file_, user=self.user, addon=self.addon, version=None
     )
     utils.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.RELEASE_CHANNEL_LISTED,
         selected_apps=[amo.FIREFOX.id, amo.ANDROID.id],
         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}),
        )

        utils.create_version_for_upload(self.addon, upload, amo.RELEASE_CHANNEL_LISTED)
        assert not self.mocks['Version.from_upload'].called
 def test_pass_parsed_data(self):
     file_ = get_addon_file('valid_webextension.xpi')
     upload = self.get_upload(
         abspath=file_, user=self.user, addon=self.addon, version=None
     )
     parsed_data = mock.Mock()
     utils.create_version_for_upload(
         self.addon, upload, amo.RELEASE_CHANNEL_LISTED, parsed_data=parsed_data
     )
     assert self.mocks['parse_addon'].call_count == 0
     self.mocks['Version.from_upload'].assert_called_with(
         upload,
         self.addon,
         amo.RELEASE_CHANNEL_LISTED,
         selected_apps=[amo.FIREFOX.id, amo.ANDROID.id],
         parsed_data=parsed_data,
     )
    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.
        utils.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.RELEASE_CHANNEL_LISTED,
            selected_apps=[amo.FIREFOX.id, amo.ANDROID.id],
            parsed_data=self.mocks['parse_addon'].return_value,
        )