Esempio n. 1
0
 def test_status_beta(self):
     # Check that the add-on + files are in the public status.
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     eq_(
         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])
     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],
                                        is_beta=True)
     # Check that it doesn't modify the public status.
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     eq_(
         File.objects.filter(version=self.current)[0].status,
         amo.STATUS_PUBLIC)
     # Check that the file created with the beta version is in beta status.
     eq_(
         File.objects.filter(version=beta_version)[0].status,
         amo.STATUS_BETA)
     # Check that the previously uploaded version is still pending.
     eq_(
         File.objects.filter(version=new_version)[0].status,
         amo.STATUS_PENDING)
Esempio n. 2
0
    def test_status_beta(self, parse_addon):
        parse_addon.return_value = {'version': u'0.1beta'}

        qs = File.objects.filter(version=self.current)
        Version.from_upload(self.upload, self.addon, [self.platform])
        eq_(sorted([q.status for q in qs.all()]),
            [amo.STATUS_UNREVIEWED, amo.STATUS_PUBLIC])
Esempio n. 3
0
    def test_status_beta(self, parse_addon):
        parse_addon.return_value = {'version': u'0.1beta'}

        qs = File.objects.filter(version=self.current)
        Version.from_upload(self.upload, self.addon, [self.platform])
        eq_(sorted([q.status for q in qs.all()]),
            [amo.STATUS_UNREVIEWED, amo.STATUS_PUBLIC])
Esempio n. 4
0
    def manifest_updated(self, manifest, upload):
        """The manifest has updated, create a version and file."""

        # This does most of the heavy work.
        Version.from_upload(upload, self, [])
        # Triggering this ensures that the current_version gets updated.
        self.update_version()
        amo.log(amo.LOG.MANIFEST_UPDATED, self)
Esempio n. 5
0
 def from_upload(cls, upload, platforms):
     from files.utils import parse_addon
     data = parse_addon(upload.path)
     fields = cls._meta.get_all_field_names()
     addon = Addon(**dict((k, v) for k, v in data.items() if k in fields))
     addon.status = amo.STATUS_NULL
     addon.default_locale = to_language(translation.get_language())
     addon.save()
     Version.from_upload(upload, addon, platforms)
     amo.log(amo.LOG.CREATE_ADDON, addon)
     log.debug('New addon %r from %r' % (addon, upload))
     return addon
Esempio n. 6
0
    def manifest_updated(self, manifest):
        """The manifest has updated, create a version and file."""
        with open(manifest) as fh:
            chunks = fh.read()

        # We'll only create a file upload when we detect that the manifest
        # has changed, otherwise we'll be creating an awful lot of these.
        upload = FileUpload.from_post(chunks, manifest, len(chunks))
        # This does most of the heavy work.
        Version.from_upload(upload, self,
                            [Platform.objects.get(id=amo.PLATFORM_ALL.id)])
        # Triggering this ensures that the current_version gets updated.
        self.update_version()
        amo.log(amo.LOG.MANIFEST_UPDATED, self)
Esempio n. 7
0
    def manifest_updated(self, manifest):
        """The manifest has updated, create a version and file."""
        with open(manifest) as fh:
            chunks = fh.read()

        # We'll only create a file upload when we detect that the manifest
        # has changed, otherwise we'll be creating an awful lot of these.
        upload = FileUpload.from_post(chunks, manifest, len(chunks))
        # This does most of the heavy work.
        Version.from_upload(upload, self,
                            [Platform.objects.get(id=amo.PLATFORM_ALL.id)])
        # Triggering this ensures that the current_version gets updated.
        self.update_version()
        amo.log(amo.LOG.MANIFEST_UPDATED, self)
Esempio n. 8
0
 def test_mobile_all_desktop_all_creates_all(self):
     version = Version.from_upload(
         self.upload, self.addon,
         [amo.PLATFORM_ALL.id, amo.PLATFORM_ALL_MOBILE.id])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform].shortname for f in files),
         ['all'])
Esempio n. 9
0
 def test_desktop_all_with_mixed_mobile_creates_platform_files(self):
     version = Version.from_upload(
         self.upload, self.addon,
         [amo.PLATFORM_ALL.id, amo.PLATFORM_ANDROID.id])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform].shortname for f in files),
         ['android', 'linux', 'mac', 'windows'])
Esempio n. 10
0
 def test_mobile_all_with_mixed_desktop_creates_platform_files(self):
     version = Version.from_upload(
         self.upload, self.addon,
         [amo.PLATFORM_LINUX.id, amo.PLATFORM_ALL_MOBILE.id])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform].shortname for f in files),
         ['android', 'linux', 'maemo'])
Esempio n. 11
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])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform].shortname for f in files),
         ['all', 'android'])
Esempio n. 12
0
 def test_multiple_platforms(self):
     platforms = [
         Platform.objects.get(pk=amo.PLATFORM_LINUX.id),
         Platform.objects.get(pk=amo.PLATFORM_MAC.id)
     ]
     assert storage.exists(self.upload.path)
     with storage.open(self.upload.path) as f:
         uploaded_hash = hashlib.md5(f.read()).hexdigest()
     version = Version.from_upload(self.upload, self.addon, platforms)
     assert not storage.exists(self.upload.path), (
         "Expected original upload to move but it still exists.")
     files = version.all_files
     eq_(len(files), 2)
     eq_(sorted([f.platform.id for f in files]),
         sorted([p.id for p in platforms]))
     eq_(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:
             eq_(
                 uploaded_hash,
                 hashlib.md5(f.read()).hexdigest(),
                 "md5 hash of %r does not match uploaded file" %
                 file.file_path)
Esempio n. 13
0
 def test_app_versions(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [self.platform])
     assert amo.FIREFOX in version.compatible_apps
     app = version.compatible_apps[amo.FIREFOX]
     eq_(app.min.version, '3.0')
     eq_(app.max.version, '3.6.*')
Esempio n. 14
0
 def test_app_versions(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [self.platform])
     assert amo.FIREFOX in version.compatible_apps
     app = version.compatible_apps[amo.FIREFOX]
     eq_(app.min.version, '3.0')
     eq_(app.max.version, '3.6.*')
Esempio n. 15
0
def status(request, addon_id, addon, webapp=False):
    form = forms.AppAppealForm(request.POST, product=addon)
    upload_form = NewWebappForm(request.POST or None, is_packaged=True,
                                addon=addon)

    if request.method == 'POST':
        if 'resubmit-app' in request.POST and form.is_valid():
            form.save()
            messages.success(request, _('App successfully resubmitted.'))
            return redirect(addon.get_dev_url('versions'))

        elif 'upload-version' in request.POST and upload_form.is_valid():
            ver = Version.from_upload(upload_form.cleaned_data['upload'],
                                      addon, [amo.PLATFORM_ALL])
            log.info('[Webapp:%s] New version created id=%s from upload: %s'
                     % (addon, ver.pk, upload_form.cleaned_data['upload']))
            return redirect(addon.get_dev_url('versions.edit', args=[ver.pk]))

    ctx = {'addon': addon, 'webapp': webapp, 'form': form,
           'upload_form': upload_form}

    if addon.status == amo.STATUS_REJECTED:
        try:
            entry = (AppLog.objects
                     .filter(addon=addon,
                             activity_log__action=amo.LOG.REJECT_VERSION.id)
                     .order_by('-created'))[0]
        except IndexError:
            entry = None
        # This contains the rejection reason and timestamp.
        ctx['rejection'] = entry and entry.activity_log

    return jingo.render(request, 'developers/apps/status.html', ctx)
Esempio n. 16
0
 def test_mobile_all_desktop_all_creates_all(self):
     all_desktop = Platform.objects.get(id=amo.PLATFORM_ALL.id)
     all_mobile = Platform.objects.get(id=amo.PLATFORM_ALL_MOBILE.id)
     version = Version.from_upload(self.upload, self.addon, [all_desktop,
                                                             all_mobile])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform.id].shortname for f in files),
         ['all'])
Esempio n. 17
0
 def test_desktop_all_with_mixed_mobile_creates_platform_files(self):
     all_desktop = Platform.objects.get(id=amo.PLATFORM_ALL.id)
     android = Platform.objects.get(id=amo.PLATFORM_ANDROID.id)
     version = Version.from_upload(self.upload, self.addon, [all_desktop,
                                                             android])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform.id].shortname for f in files),
         ['android', 'linux', 'mac', 'windows'])
Esempio n. 18
0
 def test_mobile_all_with_mixed_desktop_creates_platform_files(self):
     all_mobile = Platform.objects.get(id=amo.PLATFORM_ALL_MOBILE.id)
     linux = Platform.objects.get(id=amo.PLATFORM_LINUX.id)
     version = Version.from_upload(self.upload, self.addon, [linux,
                                                             all_mobile])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform.id].shortname for f in files),
         ['android', 'linux', 'maemo'])
Esempio n. 19
0
 def test_mobile_all_with_mixed_desktop_creates_platform_files(self):
     all_mobile = Platform.objects.get(id=amo.PLATFORM_ALL_MOBILE.id)
     linux = Platform.objects.get(id=amo.PLATFORM_LINUX.id)
     version = Version.from_upload(self.upload, self.addon,
                                   [linux, all_mobile])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform.id].shortname for f in files),
         ['android', 'linux', 'maemo'])
Esempio n. 20
0
 def test_mobile_all_desktop_all_creates_all(self):
     all_desktop = Platform.objects.get(id=amo.PLATFORM_ALL.id)
     all_mobile = Platform.objects.get(id=amo.PLATFORM_ALL_MOBILE.id)
     version = Version.from_upload(self.upload, self.addon,
                                   [all_desktop, all_mobile])
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform.id].shortname for f in files),
         ['all'])
Esempio n. 21
0
 def test_status_beta(self):
     # Create a version and switch the add-on status to public.
     Version.from_upload(self.upload, self.addon, [self.platform])
     File.objects.all().update(status=amo.STATUS_PUBLIC)
     self.addon.update(status=amo.STATUS_PUBLIC)
     # Create an under review version.
     upload = self.get_upload('extension-0.2.xpi')
     Version.from_upload(upload, self.addon, [self.platform])
     # Create a beta version.
     upload = self.get_upload('extension-0.2b1.xpi')
     version = Version.from_upload(upload, self.addon, [self.platform],
                                   is_beta=True)
     # Check that it doesn't modify the public status and that the
     # created file is in the beta status.
     eq_(File.objects.filter(version=self.current)[0].status,
         amo.STATUS_PUBLIC)
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     eq_(File.objects.filter(version=version)[0].status, amo.STATUS_BETA)
Esempio n. 22
0
def version_add(request, addon_id, addon):
    form = forms.NewVersionForm(request.POST, addon=addon)
    if form.is_valid():
        v = Version.from_upload(form.cleaned_data['upload'], addon,
                                form.cleaned_data['platforms'])
        url = reverse('devhub.versions.edit', args=[addon.slug, str(v.id)])
        return dict(url=url)
    else:
        return json_view.error(form.errors)
Esempio n. 23
0
 def test_status_beta(self):
     # Create a version and switch the add-on status to public.
     Version.from_upload(self.upload, self.addon, [self.platform])
     File.objects.all().update(status=amo.STATUS_PUBLIC)
     self.addon.update(status=amo.STATUS_PUBLIC)
     # Create an under review version.
     upload = self.get_upload('extension-0.2.xpi')
     Version.from_upload(upload, self.addon, [self.platform])
     # Create a beta version.
     upload = self.get_upload('extension-0.2b1.xpi')
     version = Version.from_upload(upload, self.addon, [self.platform],
                                   is_beta=True)
     # Check that it doesn't modify the public status and that the
     # created file is in the beta status.
     eq_(File.objects.filter(version=self.current)[0].status,
         amo.STATUS_PUBLIC)
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     eq_(File.objects.filter(version=version)[0].status, amo.STATUS_BETA)
Esempio n. 24
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]
     )
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform].shortname for f in files),
         ['all', 'android'])
Esempio n. 25
0
 def test_mobile_all_desktop_all_creates_all(self):
     version = Version.from_upload(
         self.upload,
         self.addon,
         [amo.PLATFORM_ALL.id, amo.PLATFORM_ALL_MOBILE.id]
     )
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform].shortname for f in files),
         ['all'])
Esempio n. 26
0
 def test_mobile_all_with_mixed_desktop_creates_platform_files(self):
     version = Version.from_upload(
         self.upload,
         self.addon,
         [amo.PLATFORM_LINUX.id, amo.PLATFORM_ALL_MOBILE.id]
     )
     files = version.all_files
     eq_(sorted(amo.PLATFORMS[f.platform].shortname for f in files),
         ['android', 'linux', 'maemo'])
Esempio n. 27
0
def version_add(request, addon_id, addon):
    form = forms.NewVersionForm(request.POST, addon=addon)
    if form.is_valid():
        pl = (list(form.cleaned_data['desktop_platforms']) +
              list(form.cleaned_data['mobile_platforms']))
        v = Version.from_upload(form.cleaned_data['upload'], addon, pl)
        url = reverse('devhub.versions.edit', args=[addon.slug, str(v.id)])
        return dict(url=url)
    else:
        return json_view.error(form.errors)
Esempio n. 28
0
def version_add(request, addon_id, addon):
    form = forms.NewVersionForm(request.POST, addon=addon)
    if form.is_valid():
        pl = (list(form.cleaned_data['desktop_platforms']) +
              list(form.cleaned_data['mobile_platforms']))
        v = Version.from_upload(form.cleaned_data['upload'], addon, pl)
        log.info('Version created: %s for: %s' %
                 (v.pk, form.cleaned_data['upload']))
        url = reverse('devhub.versions.edit', args=[addon.slug, str(v.id)])
        return dict(url=url)
    else:
        return json_view.error(form.errors)
Esempio n. 29
0
 def test_status_beta(self):
     # Check that the add-on + files are in the public status.
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     eq_(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])
     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],
                                        is_beta=True)
     # Check that it doesn't modify the public status.
     eq_(self.addon.status, amo.STATUS_PUBLIC)
     eq_(File.objects.filter(version=self.current)[0].status,
         amo.STATUS_PUBLIC)
     # Check that the file created with the beta version is in beta status.
     eq_(File.objects.filter(version=beta_version)[0].status,
         amo.STATUS_BETA)
     # Check that the previously uploaded version is still pending.
     eq_(File.objects.filter(version=new_version)[0].status,
         amo.STATUS_PENDING)
Esempio n. 30
0
def submit_file(addon_pk, file_pk):
    addon = Addon.unfiltered.get(pk=addon_pk)
    file_ = FileUpload.objects.get(pk=file_pk)
    validation = json.loads(file_.validation)
    if (file_.automated_signing and validation["passed_auto_validation"]) or (
        not file_.automated_signing and file_.valid
    ):
        # Import loop.
        from devhub.views import auto_sign_version

        log.info("Creating version for {file_id} that passed " "validation".format(file_id=file_pk))
        version = Version.from_upload(file_, addon, [amo.PLATFORM_ALL.id])
        auto_sign_version(version)
    else:
        log.info("Skipping version creation for {file_id} that failed " "validation".format(file_id=file_pk))
Esempio n. 31
0
 def test_developer_name_from_upload(self, parse_addon):
     parse_addon.return_value = {
         'version': '42.0',
         'developer_name': u'Mýself'
     }
     addon = Addon.objects.get(pk=337141)
     # Note: we need a valid FileUpload instance, but in the end we are not
     # using its contents since we are mocking parse_addon().
     path = os.path.join(settings.ROOT, 'apps', 'devhub', 'tests',
                                    'addons', 'mozball.webapp')
     upload = self.get_upload(abspath=path, is_webapp=True)
     platform = Platform.objects.get(pk=amo.PLATFORM_ALL.id)
     version = Version.from_upload(upload, addon, [platform])
     eq_(version.version, '42.0')
     eq_(version.developer_name, u'Mýself')
Esempio n. 32
0
 def test_developer_name_from_upload(self, parse_addon):
     parse_addon.return_value = {
         'version': '42.0',
         'developer_name': u'Mýself'
     }
     addon = Addon.objects.get(pk=337141)
     # Note: we need a valid FileUpload instance, but in the end we are not
     # using its contents since we are mocking parse_addon().
     path = os.path.join(settings.ROOT, 'mkt', 'developers', 'tests',
                         'addons', 'mozball.webapp')
     upload = self.get_upload(abspath=path, is_webapp=True)
     platform = Platform.objects.get(pk=amo.PLATFORM_ALL.id)
     version = Version.from_upload(upload, addon, [platform])
     eq_(version.version, '42.0')
     eq_(version.developer_name, u'Mýself')
Esempio n. 33
0
def submit_file(addon_pk, file_pk):
    addon = Addon.unfiltered.get(pk=addon_pk)
    file_ = FileUpload.objects.get(pk=file_pk)
    validation = json.loads(file_.validation)
    if (file_.automated_signing and validation['passed_auto_validation']) or (
            not file_.automated_signing and file_.valid):
        # Import loop.
        from devhub.views import auto_sign_version

        log.info('Creating version for {file_id} that passed '
                 'validation'.format(file_id=file_pk))
        version = Version.from_upload(file_, addon, [amo.PLATFORM_ALL.id])
        auto_sign_version(version)
    else:
        log.info('Skipping version creation for {file_id} that failed '
                 'validation'.format(file_id=file_pk))
Esempio n. 34
0
def status(request, addon_id, addon, webapp=False):
    form = forms.AppAppealForm(request.POST, product=addon)
    upload_form = NewWebappVersionForm(request.POST or None,
                                       is_packaged=True,
                                       addon=addon,
                                       request=request)

    if request.method == 'POST':
        if 'resubmit-app' in request.POST and form.is_valid():
            form.save()
            messages.success(request, _('App successfully resubmitted.'))
            return redirect(addon.get_dev_url('versions'))

        elif 'upload-version' in request.POST and upload_form.is_valid():
            ver = Version.from_upload(upload_form.cleaned_data['upload'],
                                      addon, [amo.PLATFORM_ALL])
            messages.success(request, _('New version successfully added.'))
            log.info('[Webapp:%s] New version created id=%s from upload: %s' %
                     (addon, ver.pk, upload_form.cleaned_data['upload']))
            return redirect(addon.get_dev_url('versions.edit', args=[ver.pk]))

    ctx = {
        'addon': addon,
        'webapp': webapp,
        'form': form,
        'upload_form': upload_form
    }

    # Used in the delete version modal.
    if addon.is_packaged:
        versions = addon.versions.values('id', 'version')
        version_strings = dict((v['id'], v) for v in versions)
        version_strings['num'] = len(versions)
        ctx['version_strings'] = json.dumps(version_strings)

    if addon.status == amo.STATUS_REJECTED:
        try:
            entry = (AppLog.objects.filter(
                addon=addon,
                activity_log__action=amo.LOG.REJECT_VERSION.id).order_by(
                    '-created'))[0]
        except IndexError:
            entry = None
        # This contains the rejection reason and timestamp.
        ctx['rejection'] = entry and entry.activity_log

    return jingo.render(request, 'developers/apps/status.html', ctx)
Esempio n. 35
0
def create_version_for_upload(addon, file_):
    if (addon.fileupload_set.filter(created__gt=file_.created,
                                    version=file_.version).exists()
            or addon.versions.filter(version=file_.version).exists()):
        log.info('Skipping Version creation for {file_id} that would cause '
                 'duplicate version'.format(file_id=file_.pk))
    else:
        # Import loop.
        from devhub.views import auto_sign_version

        log.info('Creating version for {file_id} that passed '
                 'validation'.format(file_id=file_.pk))
        version = Version.from_upload(file_, addon, [amo.PLATFORM_ALL.id])
        # 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)
Esempio n. 36
0
def create_version_for_upload(addon, file_):
    if (addon.fileupload_set.filter(created__gt=file_.created,
                                    version=file_.version).exists()
            or addon.versions.filter(version=file_.version).exists()):
        log.info('Skipping Version creation for {file_id} that would cause '
                 'duplicate version'.format(file_id=file_.pk))
    else:
        # Import loop.
        from devhub.views import auto_sign_version

        log.info('Creating version for {file_id} that passed '
                 'validation'.format(file_id=file_.pk))
        version = Version.from_upload(file_, addon, [amo.PLATFORM_ALL.id])
        # 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)
Esempio n. 37
0
def submit_file(addon_pk, file_pk):
    addon = Addon.unfiltered.get(pk=addon_pk)
    file_ = FileUpload.objects.get(pk=file_pk)
    if (file_.passed_all_validations and not addon.fileupload_set.filter(
            created__gt=file_.created, version=file_.version).exists()):
        # Import loop.
        from devhub.views import auto_sign_version

        log.info('Creating version for {file_id} that passed '
                 'validation'.format(file_id=file_pk))
        version = Version.from_upload(file_, addon, [amo.PLATFORM_ALL.id])
        # The add-on'sstatus 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)
    else:
        log.info('Skipping version creation for {file_id} that failed '
                 'validation'.format(file_id=file_pk))
Esempio n. 38
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.md5(file_.read()).hexdigest()
     version = Version.from_upload(self.upload, self.addon, platforms)
     assert not storage.exists(self.upload.path), (
         "Expected original upload to move but it still exists.")
     files = version.all_files
     eq_(len(files), 2)
     eq_(sorted([f.platform for f in files]),
         sorted(platforms))
     eq_(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:
             eq_(uploaded_hash,
                 hashlib.md5(f.read()).hexdigest(),
                 "md5 hash of %r does not match uploaded file" % (
                     file_.file_path))
Esempio n. 39
0
 def test_multiple_platforms(self):
     platforms = [Platform.objects.get(pk=amo.PLATFORM_LINUX.id), Platform.objects.get(pk=amo.PLATFORM_MAC.id)]
     assert os.path.exists(self.upload.path)
     with open(self.upload.path) as f:
         uploaded_hash = hashlib.md5(f.read()).hexdigest()
     version = Version.from_upload(self.upload, self.addon, platforms)
     assert not os.path.exists(self.upload.path), "Expected original upload to move but it still exists."
     files = version.all_files
     eq_(len(files), 2)
     eq_(sorted([f.platform.id for f in files]), sorted([p.id for p in platforms]))
     eq_(
         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 open(file.file_path) as f:
             eq_(
                 uploaded_hash,
                 hashlib.md5(f.read()).hexdigest(),
                 "md5 hash of %r does not match uploaded file" % file.file_path,
             )
Esempio n. 40
0
 def test_file_multi_package(self):
     version = Version.from_upload(self.get_upload('multi-package.xpi'),
                                   self.addon, [self.platform])
     files = version.all_files
     assert files[0].is_multi_package
Esempio n. 41
0
 def test_version_number(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [self.platform])
     eq_(version.version, self.now)
Esempio n. 42
0
 def test_file_name_platform_all(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [amo.PLATFORM_ALL.id])
     files = version.all_files
     eq_(files[0].filename, u'delicious_bookmarks-0.1-fx.xpi')
Esempio n. 43
0
 def test_file_platform(self):
     version = Version.from_upload(self.upload, self.addon, [self.platform])
     files = version.all_files
     eq_(len(files), 1)
     eq_(files[0].platform, self.platform)
Esempio n. 44
0
 def test_carry_over_license_no_version(self):
     self.addon.versions.all().delete()
     version = Version.from_upload(self.upload, self.addon, [self.platform])
     eq_(version.license_id, None)
Esempio n. 45
0
 def test_carry_over_old_license(self):
     version = Version.from_upload(self.upload, self.addon, [self.platform])
     eq_(version.license_id, self.addon.current_version.license_id)
Esempio n. 46
0
 def test_file_name(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [self.platform])
     files = version.all_files
     eq_(files[0].filename,
         u'delicious_bookmarks-%s.xml' % self.now)
Esempio n. 47
0
 def test_carry_over_license_no_version(self):
     self.addon.versions.all().delete()
     version = Version.from_upload(self.upload, self.addon,
                                   [self.platform])
     eq_(version.license_id, None)
Esempio n. 48
0
 def test_status(self):
     qs = File.objects.filter(version=self.current)
     Version.from_upload(self.upload, self.addon, [self.platform])
     eq_(sorted([q.status for q in qs.all()]),
         [amo.STATUS_PUBLIC, amo.STATUS_DISABLED])
Esempio n. 49
0
 def test_file_name(self):
     version = Version.from_upload(self.upload, self.addon, [self.platform])
     files = version.all_files
     eq_(files[0].filename, u'delicious_bookmarks-%s.xml' % self.now)
Esempio n. 50
0
 def test_file_platform_is_always_all(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [self.platform])
     files = version.all_files
     eq_(len(files), 1)
     eq_(files[0].platform.id, amo.PLATFORM_ALL.id)
Esempio n. 51
0
def status(request, addon_id, addon, webapp=False):
    form = forms.AppAppealForm(request.POST, product=addon)
    upload_form = NewWebappVersionForm(request.POST or None, is_packaged=True,
                                       addon=addon, request=request)

    if request.method == 'POST':
        if 'resubmit-app' in request.POST and form.is_valid():
            form.save()
            perms = ('reviewer', 'senior_reviewer', 'staff')
            create_comm_thread(action='resubmit', addon=addon,
                comments=form.data['notes'], profile=request.amo_user,
                version=addon.current_version, perms=perms)

            messages.success(request, _('App successfully resubmitted.'))
            return redirect(addon.get_dev_url('versions'))

        elif 'upload-version' in request.POST and upload_form.is_valid():
            mobile_only = (addon.latest_version and
                           addon.latest_version.features.has_qhd)

            ver = Version.from_upload(upload_form.cleaned_data['upload'],
                                      addon, [amo.PLATFORM_ALL])

            # Update addon status now that the new version was saved.
            addon.update_status()

            res = run_validator(ver.all_files[0].file_path)
            validation_result = json.loads(res)

            # Set all detected features as True and save them.
            keys = ['has_%s' % feature.lower()
                    for feature in validation_result['feature_profile']]
            data = defaultdict.fromkeys(keys, True)

            # Set "Smartphone-Sized Displays" if it's a mobile-only app.
            qhd_devices = (set((amo.DEVICE_GAIA,)),
                           set((amo.DEVICE_MOBILE,)),
                           set((amo.DEVICE_GAIA, amo.DEVICE_MOBILE,)))
            if set(addon.device_types) in qhd_devices or mobile_only:
                data['has_qhd'] = True

            # Update feature profile for this version.
            ver.features.update(**data)

            messages.success(request, _('New version successfully added.'))
            log.info('[Webapp:%s] New version created id=%s from upload: %s'
                     % (addon, ver.pk, upload_form.cleaned_data['upload']))
            return redirect(addon.get_dev_url('versions.edit', args=[ver.pk]))

    ctx = {'addon': addon, 'webapp': webapp, 'form': form,
           'upload_form': upload_form}

    # Used in the delete version modal.
    if addon.is_packaged:
        versions = addon.versions.values('id', 'version')
        version_strings = dict((v['id'], v) for v in versions)
        version_strings['num'] = len(versions)
        ctx['version_strings'] = json.dumps(version_strings)

    if addon.status == amo.STATUS_REJECTED:
        try:
            entry = (AppLog.objects
                     .filter(addon=addon,
                             activity_log__action=amo.LOG.REJECT_VERSION.id)
                     .order_by('-created'))[0]
        except IndexError:
            entry = None
        # This contains the rejection reason and timestamp.
        ctx['rejection'] = entry and entry.activity_log

    if waffle.switch_is_active('preload-apps'):
        test_plan = PreloadTestPlan.objects.filter(
            addon=addon, status=amo.STATUS_PUBLIC)
        if test_plan.exists():
            test_plan = test_plan[0]
            if (test_plan.last_submission <
                settings.PREINSTALL_TEST_PLAN_LATEST):
                ctx['outdated_test_plan'] = True
            ctx['next_step_suffix'] = 'submit'
        else:
            ctx['next_step_suffix'] = 'home'
        ctx['test_plan'] = test_plan

    return jingo.render(request, 'developers/apps/status.html', ctx)
Esempio n. 52
0
                      (xpi, e))
            continue

        if addon:
            if addon.versions.filter(version=data['version']).exists():
                log.info('[@None] Version %s of "%s" language pack exists' %
                         (data['version'], xpi))
                continue
            if not (addon.addonuser_set.filter(
                    user__email=settings.LANGPACK_OWNER_EMAIL).exists()):
                log.info('[@None] Skipping language pack "%s": '
                         'not owned by %s' %
                         (xpi, settings.LANGPACK_OWNER_EMAIL))
                continue

            version = Version.from_upload(upload, addon, PLATFORMS)
            log.info('[@None] Updating language pack "%s" to version %s' %
                     (xpi, data['version']))
        else:
            if amo.VERSION_BETA.search(data['version']):
                log.error('[@None] Not creating beta version %s for new "%s" '
                          'language pack' % (data['version'], xpi))
                continue

            addon = Addon.from_upload(upload, PLATFORMS)
            AddonUser(addon=addon, user=owner).save()
            version = addon.versions.get()

            addon.status = amo.STATUS_PUBLIC
            if addon.default_locale.lower() == lang.lower():
                addon.target_locale = addon.default_locale
Esempio n. 53
0
 def test_carry_over_old_license(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [self.platform])
     eq_(version.license_id, self.addon.current_version.license_id)
Esempio n. 54
0
 def test_status(self):
     qs = File.objects.filter(version=self.current)
     Version.from_upload(self.upload, self.addon, [self.platform])
     eq_(sorted([q.status for q in qs.all()]),
         [amo.STATUS_PUBLIC, amo.STATUS_DISABLED])
Esempio n. 55
0
 def test_version_number(self):
     version = Version.from_upload(self.upload, self.addon, [self.platform])
     eq_(version.version, self.now)
Esempio n. 56
0
 def test_file_not_multi_package(self):
     version = Version.from_upload(self.upload, self.addon, [self.platform])
     files = version.all_files
     assert not files[0].is_multi_package
Esempio n. 57
0
 def test_file_platform_is_always_all(self):
     version = Version.from_upload(self.upload, self.addon, [self.platform])
     files = version.all_files
     eq_(len(files), 1)
     eq_(files[0].platform, amo.PLATFORM_ALL.id)
Esempio n. 58
0
 def test_status(self):
     self.current.files.all().update(status=amo.STATUS_UNREVIEWED)
     Version.from_upload(self.upload, self.addon, [self.platform])
     eq_(
         File.objects.filter(version=self.current)[0].status,
         amo.STATUS_DISABLED)
Esempio n. 59
0
 def test_file_platform(self):
     version = Version.from_upload(self.upload, self.addon,
                                   [self.platform])
     files = version.all_files
     eq_(len(files), 1)
     eq_(files[0].platform, self.platform)
Esempio n. 60
0
 def test_file_name_platform_all(self):
     version = Version.from_upload(self.upload, self.addon,
                         [Platform.objects.get(pk=amo.PLATFORM_ALL.id)])
     files = version.all_files
     eq_(files[0].filename, u'delicious_bookmarks-0.1-fx.xpi')