Example #1
0
    def create(self, request):
        if not waffle.flag_is_active(request, 'accept-webapps'):
            return rc.BAD_REQUEST

        form = NewManifestForm(request.POST)
        if form.is_valid():
            # This feels like an awful lot of work.
            # But first upload the file and do the validation.
            upload = FileUpload.objects.create()
            tasks.fetch_manifest(form.cleaned_data['manifest'], upload.pk)

            # We must reget the object here since the above has
            # saved changes to the object.
            upload = FileUpload.uncached.get(pk=upload.pk)
            # Check it validated correctly.
            if settings.VALIDATE_ADDONS:
                validation = json.loads(upload.validation)
                if validation['errors']:
                    response = rc.BAD_REQUEST
                    response.write(validation)
                    return response

            # Fetch the addon, the icon and set the user.
            addon = Addon.from_upload(upload,
                        [Platform.objects.get(id=amo.PLATFORM_ALL.id)])
            tasks.fetch_icon(addon)
            AddonUser(addon=addon, user=request.amo_user).save()
            addon.update(status=amo.STATUS_PENDING if
                         settings.WEBAPPS_RESTRICTED else amo.STATUS_PUBLIC)

        else:
            return _form_error(form)
        return addon
Example #2
0
    def test_data_uri(self):
        app_path = self.apps_path / 'dataicon.webapp'
        webapp = self.webapp_from_path(app_path)

        tasks.fetch_icon(webapp)
        eq_(webapp.icon_type, self.content_type)

        self.check_icons(webapp)
Example #3
0
    def test_data_uri(self):
        app_path = self.apps_path / 'dataicon.webapp'
        webapp = self.webapp_from_path(app_path)

        tasks.fetch_icon(webapp)
        eq_(webapp.icon_type, self.content_type)

        self.check_icons(webapp)
Example #4
0
 def test_no_icons(self):
     path = self.apps_path / 'noicon.webapp'
     iconless_app = self.webapp_from_path(path)
     tasks.fetch_icon(iconless_app)
     assert not self.urlopen_mock.called
Example #5
0
 def test_no_icons(self):
     path = self.apps_path / 'noicon.webapp'
     iconless_app = self.webapp_from_path(path)
     urllib2.urlopen = mock.Mock()
     tasks.fetch_icon(iconless_app)
     assert not urllib2.urlopen.called
Example #6
0
 def test_no_icons(self):
     path = self.apps_path / 'noicon.webapp'
     iconless_app = self.webapp_from_path(path)
     urllib2.urlopen = mock.Mock()
     tasks.fetch_icon(iconless_app)
     assert not urllib2.urlopen.called
Example #7
0
 def test_no_icons(self):
     path = self.apps_path / 'noicon.webapp'
     iconless_app = self.webapp_from_path(path)
     tasks.fetch_icon(iconless_app)
     assert not self.urlopen_mock.called