Exemple #1
0
 def test_status(self):
     self.current.files.all().update(status=amo.STATUS_AWAITING_REVIEW)
     Version.from_upload(self.upload, self.addon, [self.platform],
                         amo.RELEASE_CHANNEL_LISTED,
                         parsed_data=self.dummy_parsed_data)
     assert File.objects.filter(version=self.current)[0].status == (
         amo.STATUS_DISABLED)
Exemple #2
0
 def test_status_beta(self):
     # Check that the add-on + files are in the public status.
     assert self.addon.status == amo.STATUS_PUBLIC
     assert File.objects.filter(version=self.current)[0].status == (
         amo.STATUS_PUBLIC)
     # Create a new under review version with a pending file.
     upload = self.get_upload('extension-0.2.xpi')
     new_version = Version.from_upload(upload, self.addon, [self.platform],
                                       amo.RELEASE_CHANNEL_LISTED)
     new_version.files.all()[0].update(status=amo.STATUS_PENDING)
     # Create a beta version.
     upload = self.get_upload('extension-0.2b1.xpi')
     beta_version = Version.from_upload(upload, self.addon, [self.platform],
                                        amo.RELEASE_CHANNEL_LISTED,
                                        is_beta=True)
     # Check that it doesn't modify the public status.
     assert self.addon.status == amo.STATUS_PUBLIC
     assert File.objects.filter(version=self.current)[0].status == (
         amo.STATUS_PUBLIC)
     # Check that the file created with the beta version is in beta status.
     assert File.objects.filter(version=beta_version)[0].status == (
         amo.STATUS_BETA)
     # Check that the previously uploaded version is still pending.
     assert File.objects.filter(version=new_version)[0].status == (
         amo.STATUS_PENDING)
Exemple #3
0
 def test_carry_over_license_no_version(self):
     self.addon.versions.all().delete()
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=self.dummy_parsed_data)
     assert version.license_id is None
Exemple #4
0
def create_version_for_upload(addon, upload):
    fileupload_exists = addon.fileupload_set.filter(
        created__gt=upload.created, version=upload.version).exists()
    version_exists = Version.unfiltered.filter(
        addon=addon, version=upload.version).exists()
    if (fileupload_exists or version_exists):
        log.info('Skipping Version creation for {upload_uuid} that would '
                 ' cause duplicate version'.format(upload_uuid=upload.uuid))
    else:
        # Import loop.
        from olympia.devhub.views import auto_sign_version

        log.info('Creating version for {upload_uuid} that passed '
                 'validation'.format(upload_uuid=upload.uuid))
        beta = bool(upload.version) and is_beta(upload.version)
        version = Version.from_upload(
            upload, addon, [amo.PLATFORM_ALL.id], is_beta=beta)
        # The add-on's status will be STATUS_NULL when its first version is
        # created because the version has no files when it gets added and it
        # gets flagged as invalid. We need to manually set the status.
        # TODO: Handle sideload add-ons. This assumes the user wants a prelim
        # review since listed and sideload aren't supported for creation yet.
        if addon.status == amo.STATUS_NULL:
            addon.update(status=amo.STATUS_LITE)
        auto_sign_version(version, is_beta=version.is_beta)
Exemple #5
0
 def test_file_not_multi_package(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     files = version.all_files
     assert not files[0].is_multi_package
Exemple #6
0
def create_version_for_upload(addon, upload):
    fileupload_exists = addon.fileupload_set.filter(
        created__gt=upload.created, version=upload.version).exists()
    version_exists = Version.unfiltered.filter(
        addon=addon, version=upload.version).exists()
    if (fileupload_exists or version_exists):
        log.info('Skipping Version creation for {upload_uuid} that would '
                 ' cause duplicate version'.format(upload_uuid=upload.uuid))
    else:
        # Import loop.
        from olympia.devhub.views import auto_sign_version

        log.info('Creating version for {upload_uuid} that passed '
                 'validation'.format(upload_uuid=upload.uuid))
        beta = (addon.is_listed and
                bool(upload.version) and is_beta(upload.version))
        version = Version.from_upload(
            upload, addon, [amo.PLATFORM_ALL.id], is_beta=beta)
        # The add-on's status will be STATUS_NULL when its first version is
        # created because the version has no files when it gets added and it
        # gets flagged as invalid. We need to manually set the status.
        #
        # Note: this assumes the developer wants a full review. This makes
        # sense for now because this function is only called from
        # submit_file(), which is itself only called from the signing API,
        # which only supports unlisted add-ons, and unlisted add-ons are
        # supposed to automatically be set as fully reviewed once signed.
        if addon.status == amo.STATUS_NULL:
            addon.update(status=amo.STATUS_NOMINATED)
        auto_sign_version(version, is_beta=version.is_beta)
Exemple #7
0
 def test_version_number(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     assert version.version == self.now
Exemple #8
0
 def test_app_versions(self):
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED)
     assert amo.FIREFOX in version.compatible_apps
     app = version.compatible_apps[amo.FIREFOX]
     assert app.min.version == '3.0'
     assert app.max.version == '3.6.*'
Exemple #9
0
 def test_android_creates_platform_files(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [amo.PLATFORM_ANDROID.id],
                                   amo.RELEASE_CHANNEL_LISTED)
     files = version.all_files
     assert sorted(amo.PLATFORMS[f.platform].shortname for f in files) == (
         ['android'])
Exemple #10
0
def create_version_for_upload(addon, upload, channel):
    """Note this function is only used for API uploads."""
    fileupload_exists = addon.fileupload_set.filter(
        created__gt=upload.created, version=upload.version).exists()
    version_exists = Version.unfiltered.filter(
        addon=addon, version=upload.version).exists()
    if (fileupload_exists or version_exists):
        log.info('Skipping Version creation for {upload_uuid} that would '
                 ' cause duplicate version'.format(upload_uuid=upload.uuid))
    else:
        # Import loop.
        from olympia.devhub.views import auto_sign_version

        log.info('Creating version for {upload_uuid} that passed '
                 'validation'.format(upload_uuid=upload.uuid))
        beta = bool(upload.version) and is_beta(upload.version)
        version = Version.from_upload(
            upload, addon, [amo.PLATFORM_ALL.id], channel,
            is_beta=beta)
        # The add-on's status will be STATUS_NULL when its first version is
        # created because the version has no files when it gets added and it
        # gets flagged as invalid. We need to manually set the status.
        if (addon.status == amo.STATUS_NULL and
                channel == amo.RELEASE_CHANNEL_LISTED):
            addon.update(status=amo.STATUS_NOMINATED)
        auto_sign_version(version, is_beta=version.is_beta)
Exemple #11
0
def create_version_for_upload(addon, upload, channel):
    """Note this function is only used for API uploads."""
    fileupload_exists = addon.fileupload_set.filter(
        created__gt=upload.created, version=upload.version).exists()
    version_exists = Version.unfiltered.filter(
        addon=addon, version=upload.version).exists()
    if (fileupload_exists or version_exists):
        log.info('Skipping Version creation for {upload_uuid} that would '
                 ' cause duplicate version'.format(upload_uuid=upload.uuid))
    else:
        # Import loop.
        from olympia.devhub.utils import add_dynamic_theme_tag
        from olympia.devhub.views import auto_sign_version

        log.info('Creating version for {upload_uuid} that passed '
                 'validation'.format(upload_uuid=upload.uuid))
        # Note: if we somehow managed to get here with an invalid add-on,
        # parse_addon() will raise ValidationError and the task will fail
        # loudly in sentry.
        parsed_data = parse_addon(upload, addon, user=upload.user)
        version = Version.from_upload(
            upload, addon, [x[0] for x in amo.APPS_CHOICES],
            channel,
            parsed_data=parsed_data)
        # The add-on's status will be STATUS_NULL when its first version is
        # created because the version has no files when it gets added and it
        # gets flagged as invalid. We need to manually set the status.
        if (addon.status == amo.STATUS_NULL and
                channel == amo.RELEASE_CHANNEL_LISTED):
            addon.update(status=amo.STATUS_NOMINATED)
        auto_sign_version(version)
        add_dynamic_theme_tag(version)
Exemple #12
0
 def test_file_name(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     files = version.all_files
     assert files[0].filename == u'delicious_bookmarks-0.1-fx-mac.xpi'
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)
Exemple #14
0
 def test_mozilla_signed_extension(self):
     self.dummy_parsed_data['is_mozilla_signed_extension'] = True
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED, parsed_data=self.dummy_parsed_data)
     assert version.is_mozilla_signed
     assert version.approval_notes == (u'This version has been signed with '
                                       u'Mozilla internal certificate.')
Exemple #15
0
 def test_file_platform_is_always_all(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     files = version.all_files
     assert len(files) == 1
     assert files[0].platform == amo.PLATFORM_ALL.id
Exemple #16
0
 def test_new_version_is_10s_compatible_no_feature_compat_previously(self):
     assert not self.addon.feature_compatibility.pk
     self.upload = self.get_upload('multiprocess_compatible_extension.xpi')
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED)
     assert version.pk
     assert self.addon.feature_compatibility.pk
     assert self.addon.feature_compatibility.e10s == amo.E10S_COMPATIBLE
Exemple #17
0
 def test_app_versions(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     assert amo.FIREFOX in version.compatible_apps
     app = version.compatible_apps[amo.FIREFOX]
     assert app.min.version == '3.0'
     assert app.max.version == '3.6.*'
Exemple #18
0
 def test_file_name(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     files = version.all_files
     assert files[0].filename == (
         u'delicious_bookmarks-%s.xml' % self.now)
Exemple #19
0
 def test_file_multi_package(self):
     self.upload = self.get_upload('multi-package.xpi')
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     files = version.all_files
     assert files[0].is_multi_package
Exemple #20
0
 def test_new_version_while_public(
         self, generate_static_theme_preview_mock):
     self.addon = addon_factory(type=amo.ADDON_STATICTHEME)
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [], amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     assert len(version.all_files) == 1
     assert generate_static_theme_preview_mock.call_count == 1
Exemple #21
0
 def test_file_name(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     files = version.all_files
     assert files[0].filename == (
         u'delicious_bookmarks-%s.xml' % self.now)
Exemple #22
0
 def test_mozilla_signed_extension(self):
     self.dummy_parsed_data['is_mozilla_signed_extension'] = True
     version = Version.from_upload(self.upload,
                                   self.addon, [self.selected_app],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=self.dummy_parsed_data)
     assert version.is_mozilla_signed
     assert version.approval_notes == (u'This version has been signed with '
                                       u'Mozilla internal certificate.')
Exemple #23
0
    def test_commits_to_git_async_only_if_version_created(
            self, utc_millisecs_mock, extract_mock):
        utc_millisecs_mock.side_effect = ValueError
        addon = addon_factory()
        upload = self.get_upload('webextension_no_id.xpi')
        upload.user = user_factory(username='******')
        parsed_data = parse_addon(upload, addon, user=upload.user)

        # Simulating an atomic transaction similar to what
        # create_version_for_upload does
        with pytest.raises(ValueError):
            with transaction.atomic():
                Version.from_upload(
                    upload, addon, [amo.FIREFOX.id],
                    amo.RELEASE_CHANNEL_LISTED,
                    parsed_data=parsed_data)

        extract_mock.assert_not_called()
Exemple #24
0
 def test_file_platform_is_always_all(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload,
                                   self.addon, [self.selected_app],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     files = version.all_files
     assert len(files) == 1
     assert files[0].platform == amo.PLATFORM_ALL.id
Exemple #25
0
    def test_track_upload_time(self):
        # Set created time back (just for sanity) otherwise the delta
        # would be in the microsecond range.
        self.upload.update(created=datetime.now() - timedelta(days=1))

        mock_timing_path = 'olympia.versions.models.statsd.timing'
        with mock.patch(mock_timing_path) as mock_timing:
            Version.from_upload(self.upload, self.addon, [self.platform],
                                amo.RELEASE_CHANNEL_LISTED)

            upload_start = utc_millesecs_from_epoch(self.upload.created)
            now = utc_millesecs_from_epoch()
            rough_delta = now - upload_start
            actual_delta = mock_timing.call_args[0][1]

            fuzz = 2000  # 2 seconds
            assert (actual_delta >= (rough_delta - fuzz) and
                    actual_delta <= (rough_delta + fuzz))
Exemple #26
0
 def test_file_multi_package(self):
     self.upload = self.get_upload('multi-package.xpi')
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload,
                                   self.addon, [self.selected_app],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     files = version.all_files
     assert files[0].is_multi_package
Exemple #27
0
    def test_commits_to_git_async_only_if_version_created(
            self, utc_millisecs_mock, extract_mock):
        utc_millisecs_mock.side_effect = ValueError
        addon = addon_factory()
        upload = self.get_upload('webextension_no_id.xpi')
        upload.user = user_factory(username='******')
        parsed_data = parse_addon(upload, addon, user=upload.user)

        # Simulating an atomic transaction similar to what
        # create_version_for_upload does
        with pytest.raises(ValueError):
            with transaction.atomic():
                Version.from_upload(upload,
                                    addon, [amo.FIREFOX.id],
                                    amo.RELEASE_CHANNEL_LISTED,
                                    parsed_data=parsed_data)

        extract_mock.assert_not_called()
Exemple #28
0
 def test_new_version_while_public(
         self, generate_static_theme_preview_mock):
     self.addon = addon_factory(type=amo.ADDON_STATICTHEME)
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [], amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     assert len(version.all_files) == 1
     assert generate_static_theme_preview_mock.call_count == 1
def add_static_theme_from_lwt(lwt):
    # Try to handle LWT with no authors
    author = (lwt.listed_authors or [_get_lwt_default_author()])[0]
    # Wrap zip in FileUpload for Addon/Version from_upload to consume.
    upload = FileUpload.objects.create(
        user=author, valid=True)
    destination = os.path.join(
        user_media_path('addons'), 'temp', uuid.uuid4().hex + '.xpi')
    build_static_theme_xpi_from_lwt(lwt, destination)
    upload.update(path=destination)

    # Create addon + version
    parsed_data = parse_addon(upload, user=author)
    addon = Addon.initialize_addon_from_upload(
        parsed_data, upload, amo.RELEASE_CHANNEL_LISTED, author)
    # Version.from_upload sorts out platforms for us.
    version = Version.from_upload(
        upload, addon, platforms=None, channel=amo.RELEASE_CHANNEL_LISTED,
        parsed_data=parsed_data)

    # Set category
    static_theme_categories = CATEGORIES.get(amo.FIREFOX.id, []).get(
        amo.ADDON_STATICTHEME, [])
    lwt_category = (lwt.categories.all() or [None])[0]  # lwt only have 1 cat.
    lwt_category_slug = lwt_category.slug if lwt_category else 'other'
    static_category = static_theme_categories.get(
        lwt_category_slug, static_theme_categories.get('other'))
    AddonCategory.objects.create(
        addon=addon,
        category=Category.from_static_category(static_category, True))

    # Set license
    lwt_license = PERSONA_LICENSES_IDS.get(
        lwt.persona.license, LICENSE_COPYRIGHT_AR)  # default to full copyright
    static_license = License.objects.get(builtin=lwt_license.builtin)
    version.update(license=static_license)

    # Set tags
    for addon_tag in AddonTag.objects.filter(addon=lwt):
        AddonTag.objects.create(addon=addon, tag=addon_tag.tag)

    # Logging
    activity.log_create(
        amo.LOG.CREATE_STATICTHEME_FROM_PERSONA, addon, user=author)
    log.debug('New static theme %r created from %r' % (addon, lwt))

    # And finally sign the files (actually just one)
    for file_ in version.all_files:
        sign_file(file_)
        file_.update(
            datestatuschanged=datetime.now(),
            reviewed=datetime.now(),
            status=amo.STATUS_PUBLIC)
    addon.update(status=amo.STATUS_PUBLIC)

    return addon
Exemple #30
0
    def test_track_upload_time(self):
        # Set created time back (just for sanity) otherwise the delta
        # would be in the microsecond range.
        self.upload.update(created=datetime.now() - timedelta(days=1))

        mock_timing_path = 'olympia.versions.models.statsd.timing'
        with mock.patch(mock_timing_path) as mock_timing:
            Version.from_upload(self.upload, self.addon, [self.platform],
                                amo.RELEASE_CHANNEL_LISTED,
                                parsed_data=self.dummy_parsed_data)

            upload_start = utc_millesecs_from_epoch(self.upload.created)
            now = utc_millesecs_from_epoch()
            rough_delta = now - upload_start
            actual_delta = mock_timing.call_args[0][1]

            fuzz = 2000  # 2 seconds
            assert (actual_delta >= (rough_delta - fuzz) and
                    actual_delta <= (rough_delta + fuzz))
Exemple #31
0
 def test_new_version_is_10s_compatible_no_feature_compat_previously(self):
     assert not self.addon.feature_compatibility.pk
     self.upload = self.get_upload('multiprocess_compatible_extension.xpi')
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     assert version.pk
     assert self.addon.feature_compatibility.pk
     assert self.addon.feature_compatibility.e10s == amo.E10S_COMPATIBLE
Exemple #32
0
 def test_creates_platform_files(self):
     # We are creating files for 'all' platforms every time, #8752
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     files = version.all_files
     assert sorted(amo.PLATFORMS[f.platform].shortname for f in files) == (
         ['all'])
 def test_app_versions(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload,
                                   self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     assert amo.FIREFOX in version.compatible_apps
     app = version.compatible_apps[amo.FIREFOX]
     assert app.min.version == '3.0'
     assert app.max.version == '3.6.*'
Exemple #34
0
 def test_desktop_all_android_creates_all(self):
     version = Version.from_upload(
         self.upload,
         self.addon,
         [amo.PLATFORM_ALL.id, amo.PLATFORM_ANDROID.id],
         amo.RELEASE_CHANNEL_LISTED
     )
     files = version.all_files
     assert sorted(amo.PLATFORMS[f.platform].shortname for f in files) == (
         ['all', 'android'])
Exemple #35
0
 def test_android_with_mixed_desktop_creates_platform_files(self):
     version = Version.from_upload(
         self.upload,
         self.addon,
         [amo.PLATFORM_LINUX.id, amo.PLATFORM_ANDROID.id],
         amo.RELEASE_CHANNEL_LISTED
     )
     files = version.all_files
     assert sorted(amo.PLATFORMS[f.platform].shortname for f in files) == (
         ['android', 'linux'])
Exemple #36
0
 def test_new_version_is_10s_compatible(self):
     AddonFeatureCompatibility.objects.create(addon=self.addon)
     assert self.addon.feature_compatibility.e10s == amo.E10S_UNKNOWN
     self.upload = self.get_upload('multiprocess_compatible_extension.xpi')
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED)
     assert version.pk
     assert self.addon.feature_compatibility.pk
     self.addon.feature_compatibility.reload()
     assert self.addon.feature_compatibility.e10s == amo.E10S_COMPATIBLE
Exemple #37
0
 def test_new_version_is_10s_compatible(self):
     AddonFeatureCompatibility.objects.create(addon=self.addon)
     assert self.addon.feature_compatibility.e10s == amo.E10S_UNKNOWN
     self.upload = self.get_upload('multiprocess_compatible_extension.xpi')
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED)
     assert version.pk
     assert self.addon.feature_compatibility.pk
     self.addon.feature_compatibility.reload()
     assert self.addon.feature_compatibility.e10s == amo.E10S_COMPATIBLE
 def test_creates_platform_files(self):
     # We are creating files for 'all' platforms every time, #8752
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload,
                                   self.addon, [self.selected_app],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     files = version.all_files
     assert sorted(amo.PLATFORMS[f.platform].shortname
                   for f in files) == (['all'])
Exemple #39
0
 def test_new_version_is_10s_compatible_no_feature_compat_previously(self):
     assert not self.addon.feature_compatibility.pk
     self.upload = self.get_upload('multiprocess_compatible_extension.xpi')
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     assert version.pk
     assert self.addon.feature_compatibility.pk
     assert self.addon.feature_compatibility.e10s == amo.E10S_COMPATIBLE
 def test_file_name(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload,
                                   self.addon, [self.selected_app],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     files = version.all_files
     # Since https://github.com/mozilla/addons-server/issues/8752 we are
     # selecting PLATFORM_ALL every time as a temporary measure until
     # platforms get removed.
     assert files[0].filename == u'delicious_bookmarks-0.1-fx.xpi'
Exemple #41
0
 def test_new_version_while_public(self,
                                   generate_static_theme_preview_mock):
     self.addon = addon_factory(type=amo.ADDON_STATICTHEME)
     version = Version.from_upload(self.upload, self.addon, [],
                                   amo.RELEASE_CHANNEL_LISTED)
     assert len(version.all_files) == 1
     assert generate_static_theme_preview_mock.delay.call_count == 1
     assert version.get_background_image_urls() == [
         '%s/%s/%s/%s' % (user_media_url('addons'), str(
             self.addon.id), unicode(version.id), 'weta.png')
     ]
Exemple #42
0
 def test_nomination_inherited_for_updates(self):
     assert self.addon.status == amo.STATUS_PUBLIC
     self.addon.current_version.update(nomination=self.days_ago(2))
     pending_version = version_factory(
         addon=self.addon, nomination=self.days_ago(1), version='9.9',
         file_kw={'status': amo.STATUS_AWAITING_REVIEW})
     assert pending_version.nomination
     upload_version = Version.from_upload(
         self.upload, self.addon, [self.platform],
         amo.RELEASE_CHANNEL_LISTED)
     assert upload_version.nomination == pending_version.nomination
Exemple #43
0
 def test_nomination_inherited_for_updates(self):
     assert self.addon.status == amo.STATUS_PUBLIC
     self.addon.current_version.update(nomination=self.days_ago(2))
     pending_version = version_factory(
         addon=self.addon, nomination=self.days_ago(1), version='9.9',
         file_kw={'status': amo.STATUS_AWAITING_REVIEW})
     assert pending_version.nomination
     upload_version = Version.from_upload(
         self.upload, self.addon, [self.platform],
         amo.RELEASE_CHANNEL_LISTED)
     assert upload_version.nomination == pending_version.nomination
Exemple #44
0
 def test_file_name(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [self.selected_app],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     files = version.all_files
     # Since https://github.com/mozilla/addons-server/issues/8752 we are
     # selecting PLATFORM_ALL every time as a temporary measure until
     # platforms get removed.
     assert files[0].filename == u'delicious_bookmarks-0.1-fx.xpi'
Exemple #45
0
 def test_new_version_with_additional_backgrounds(
         self, generate_static_theme_preview_mock):
     self.addon = addon_factory(type=amo.ADDON_STATICTHEME)
     path = 'src/olympia/devhub/tests/addons/static_theme_tiled.zip'
     self.upload = self.get_upload(
         abspath=os.path.join(settings.ROOT, path))
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload, self.addon, [], amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data)
     assert len(version.all_files) == 1
     assert generate_static_theme_preview_mock.call_count == 1
Exemple #46
0
 def test_new_version_is_webextension(self):
     self.addon.update(guid='@webextension-guid')
     AddonFeatureCompatibility.objects.create(addon=self.addon)
     assert self.addon.feature_compatibility.e10s == amo.E10S_UNKNOWN
     self.upload = self.get_upload('webextension.xpi')
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED)
     assert version.pk
     assert self.addon.feature_compatibility.pk
     self.addon.feature_compatibility.reload()
     assert self.addon.feature_compatibility.e10s == (
         amo.E10S_COMPATIBLE_WEBEXTENSION)
Exemple #47
0
 def test_android_with_mixed_desktop_creates_platform_files(self):
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(
         self.upload,
         self.addon,
         [amo.PLATFORM_LINUX.id, amo.PLATFORM_ANDROID.id],
         amo.RELEASE_CHANNEL_LISTED,
         parsed_data=parsed_data,
     )
     files = version.all_files
     assert sorted(amo.PLATFORMS[f.platform].shortname for f in files) == (
         ['android', 'linux'])
Exemple #48
0
 def test_new_version_is_webextension(self):
     self.addon.update(guid='@webextension-guid')
     AddonFeatureCompatibility.objects.create(addon=self.addon)
     assert self.addon.feature_compatibility.e10s == amo.E10S_UNKNOWN
     self.upload = self.get_upload('webextension.xpi')
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED)
     assert version.pk
     assert self.addon.feature_compatibility.pk
     self.addon.feature_compatibility.reload()
     assert self.addon.feature_compatibility.e10s == (
         amo.E10S_COMPATIBLE_WEBEXTENSION)
Exemple #49
0
    def test_commits_to_git_waffle_enabled(self):
        addon = addon_factory()
        upload = self.get_upload('webextension_no_id.xpi')
        user = user_factory(username='******')
        parsed_data = parse_addon(upload, addon, user=user)
        version = Version.from_upload(
            upload, addon, [self.selected_app],
            amo.RELEASE_CHANNEL_LISTED,
            parsed_data=parsed_data)
        assert version.pk

        repo = AddonGitRepository(addon.pk)
        assert os.path.exists(repo.git_repository_path)
 def test_new_version_is_10s_compatible(self):
     AddonFeatureCompatibility.objects.create(addon=self.addon)
     assert self.addon.feature_compatibility.e10s == amo.E10S_UNKNOWN
     self.upload = self.get_upload('multiprocess_compatible_extension.xpi')
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload,
                                   self.addon, [self.selected_app],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     assert version.pk
     assert self.addon.feature_compatibility.pk
     self.addon.feature_compatibility.reload()
     assert self.addon.feature_compatibility.e10s == amo.E10S_COMPATIBLE
Exemple #51
0
 def test_new_version_while_nominated(self,
                                      generate_static_theme_preview_mock):
     self.addon = addon_factory(
         type=amo.ADDON_STATICTHEME,
         status=amo.STATUS_NOMINATED,
         file_kw={'status': amo.STATUS_AWAITING_REVIEW})
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload,
                                   self.addon, [],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     assert len(version.all_files) == 1
     assert generate_static_theme_preview_mock.call_count == 1
Exemple #52
0
    def test_commits_to_git_async(self, extract_mock):
        addon = addon_factory()
        upload = self.get_upload('webextension_no_id.xpi')
        upload.user = user_factory(username='******')
        parsed_data = parse_addon(upload, addon, user=upload.user)
        version = Version.from_upload(
            upload, addon, [self.selected_app],
            amo.RELEASE_CHANNEL_LISTED,
            parsed_data=parsed_data)
        assert version.pk

        # Only once instead of twice
        extract_mock.assert_called_once_with(
            version_id=version.pk, author_id=upload.user.pk)
Exemple #53
0
    def test_doesnt_commit_to_git_by_default(self):
        addon = addon_factory()
        upload = self.get_upload('webextension_no_id.xpi')
        user = user_factory(username='******')
        parsed_data = parse_addon(upload, addon, user=user)

        with transaction.atomic():
            version = Version.from_upload(upload,
                                          addon, [amo.FIREFOX.id],
                                          amo.RELEASE_CHANNEL_LISTED,
                                          parsed_data=parsed_data)
        assert version.pk

        repo = AddonGitRepository(addon.pk)
        assert not os.path.exists(repo.git_repository_path)
Exemple #54
0
 def test_duplicate_target_apps(self):
     # Note: the validator prevents this, but we also need to make sure
     # overriding failed validation is possible, so we need an extra check
     # in addons-server code.
     self.filename = 'duplicate_target_applications.xpi'
     self.addon.update(guid='duplicatetargetapps@xpi')
     self.upload = self.get_upload(self.filename)
     version = Version.from_upload(self.upload, self.addon, [self.platform],
                                   amo.RELEASE_CHANNEL_LISTED)
     compatible_apps = version.compatible_apps
     assert len(compatible_apps) == 1
     assert amo.FIREFOX in version.compatible_apps
     app = version.compatible_apps[amo.FIREFOX]
     assert app.min.version == '3.0'
     assert app.max.version == '3.6.*'
Exemple #55
0
    def test_new_version_with_additional_backgrounds(
            self, generate_static_theme_preview_mock):
        addon = addon_factory(type=amo.ADDON_STATICTHEME)
        path = 'src/olympia/devhub/tests/addons/static_theme_tiled.zip'
        upload = self.get_upload(abspath=os.path.join(settings.ROOT, path))
        version = Version.from_upload(upload, addon, [],
                                      amo.RELEASE_CHANNEL_LISTED)
        assert len(version.all_files) == 1
        assert generate_static_theme_preview_mock.delay.call_count == 1
        image_url_folder = u'%s/%s/%s/' % (user_media_url('addons'), addon.id,
                                           version.id)

        assert sorted(version.get_background_image_urls()) == [
            image_url_folder + 'empty.png',
            image_url_folder + 'transparent.gif',
            image_url_folder + 'weta_for_tiling.png',
        ]
 def test_new_version_while_nominated(self,
                                      generate_static_theme_preview_mock):
     self.addon = addon_factory(
         type=amo.ADDON_STATICTHEME,
         status=amo.STATUS_NOMINATED,
         file_kw={'status': amo.STATUS_AWAITING_REVIEW})
     parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
     version = Version.from_upload(self.upload,
                                   self.addon, [],
                                   amo.RELEASE_CHANNEL_LISTED,
                                   parsed_data=parsed_data)
     assert len(version.all_files) == 1
     assert generate_static_theme_preview_mock.call_count == 1
     assert version.get_background_image_urls() == [
         '%s/%s/%s/%s' % (user_media_url('addons'), str(
             self.addon.id), unicode(version.id), 'weta.png')
     ]
Exemple #57
0
def create_version_for_upload(addon, upload, channel, parsed_data=None):
    fileupload_exists = addon.fileupload_set.filter(
        created__gt=upload.created, version=upload.version
    ).exists()
    version_exists = Version.unfiltered.filter(
        addon=addon, version=upload.version
    ).exists()
    if fileupload_exists or version_exists:
        log.info(
            'Skipping Version creation for {upload_uuid} that would '
            ' cause duplicate version'.format(upload_uuid=upload.uuid)
        )
        return None
    else:
        log.info(
            'Creating version for {upload_uuid} that passed '
            'validation'.format(upload_uuid=upload.uuid)
        )
        # Note: if we somehow managed to get here with an invalid add-on,
        # parse_addon() will raise ValidationError and the task will fail
        # loudly in sentry.
        if parsed_data is None:
            parsed_data = parse_addon(upload, addon, user=upload.user)
        new_addon = not Version.unfiltered.filter(addon=addon).exists()
        version = Version.from_upload(
            upload,
            addon,
            channel,
            selected_apps=[x[0] for x in amo.APPS_CHOICES],
            parsed_data=parsed_data,
        )
        channel_name = amo.CHANNEL_CHOICES_API[channel]
        # This function is only called via the signing api flow
        statsd.incr(
            f'signing.submission.{"addon" if new_addon else "version"}.{channel_name}'
        )
        # The add-on's status will be STATUS_NULL when its first version is
        # created because the version has no files when it gets added and it
        # gets flagged as invalid. We need to manually set the status.
        if addon.status == amo.STATUS_NULL and channel == amo.RELEASE_CHANNEL_LISTED:
            addon.update(status=amo.STATUS_NOMINATED)
        return version
Exemple #58
0
 def test_multiple_platforms(self):
     platforms = [amo.PLATFORM_LINUX.id, amo.PLATFORM_MAC.id]
     assert storage.exists(self.upload.path)
     with storage.open(self.upload.path) as file_:
         uploaded_hash = hashlib.sha256(file_.read()).hexdigest()
     version = Version.from_upload(self.upload, self.addon, platforms,
                                   amo.RELEASE_CHANNEL_LISTED)
     assert not storage.exists(self.upload.path), (
         "Expected original upload to move but it still exists.")
     files = version.all_files
     assert len(files) == 2
     assert sorted([f.platform for f in files]) == (sorted(platforms))
     assert sorted([f.filename for f in files]) == ([
         u'delicious_bookmarks-0.1-fx-%s.xpi' %
         (amo.PLATFORM_LINUX.shortname),
         u'delicious_bookmarks-0.1-fx-%s.xpi' % (amo.PLATFORM_MAC.shortname)
     ])
     for file_ in files:
         with storage.open(file_.file_path) as f:
             assert uploaded_hash == hashlib.sha256(f.read()).hexdigest()
    def test_platform_files_created(self):
        assert storage.exists(self.upload.path)
        with storage.open(self.upload.path) as file_:
            uploaded_hash = hashlib.sha256(file_.read()).hexdigest()
        parsed_data = parse_addon(self.upload, self.addon, user=mock.Mock())
        version = Version.from_upload(self.upload,
                                      self.addon,
                                      [amo.FIREFOX.id, amo.ANDROID.id],
                                      amo.RELEASE_CHANNEL_LISTED,
                                      parsed_data=parsed_data)
        assert not storage.exists(self.upload.path), (
            "Expected original upload to move but it still exists.")
        files = version.all_files
        assert len(files) == 1
        assert sorted([f.platform for f in files]) == [amo.PLATFORM_ALL.id]
        assert sorted([f.filename
                       for f in files]) == [u'delicious_bookmarks-0.1-fx.xpi']

        with storage.open(files[0].file_path) as f:
            assert uploaded_hash == hashlib.sha256(f.read()).hexdigest()