Пример #1
0
    def test_success_call_validator(self, validator_mock):
        with self.patch_urlopen() as ur:
            ct = self.content_type + '; charset=utf-8'
            ur.headers = {'Content-Type': ct}

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        assert validator_mock.called
Пример #2
0
    def create(self, request, *args, **kwargs):
        """
        Custom create method allowing us to re-use form logic and distinguish
        packaged app from hosted apps, applying delays to the validation task
        if necessary.

        Doesn't rely on any serializer, just forms.
        """
        data = self.request.DATA
        packaged = 'upload' in data
        form = (NewPackagedForm(data) if packaged else NewManifestForm(data))

        if not form.is_valid():
            return Response(form.errors, status=HTTP_400_BAD_REQUEST)

        if not packaged:
            upload = FileUpload.objects.create(
                user=request.user if request.user.is_authenticated() else None)
            # The hosted app validator is pretty fast.
            tasks.fetch_manifest(form.cleaned_data['manifest'], upload.pk)
        else:
            upload = form.file_upload
            # The packaged app validator is much heavier.
            tasks.validator.delay(upload.pk)

        log.info('Validation created: %s' % upload.pk)
        self.kwargs = {'pk': upload.pk}
        # Re-fetch the object, fetch_manifest() might have altered it.
        upload = self.get_object()
        serializer = self.get_serializer(upload)
        status = HTTP_201_CREATED if upload.processed else HTTP_202_ACCEPTED
        return Response(serializer.data, status=status)
Пример #3
0
 def test_other_url_error(self):
     reason = Exception('Some other failure.')
     self.requests_mock.side_effect = RequestException(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and try '
         'again.')
Пример #4
0
    def test_success_call_validator(self, validator_mock):
        with self.patch_requests() as ur:
            ct = self.content_type + "; charset=utf-8"
            ur.headers = {"content-type": ct}

        tasks.fetch_manifest("http://xx.com/manifest.json", self.upload.pk)
        assert validator_mock.called
Пример #5
0
    def test_response_too_large(self):
        with self.patch_urlopen() as ur:
            content = 'x' * (settings.MAX_WEBAPP_UPLOAD_SIZE + 1)
            ur.read.return_value = content

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation('Your manifest must be less than 2097152 bytes.')
Пример #6
0
 def test_http_error(self):
     self.urlopen_mock.side_effect = urllib2.HTTPError(
         'url', 404, 'Not Found', [], None)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and try '
         'again.')
Пример #7
0
 def test_connection_error(self):
     reason = socket.gaierror(8, 'nodename nor servname provided')
     self.requests_mock.side_effect = RequestException(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and try '
         'again.')
Пример #8
0
    def test_detail_for_free_extension_webapp(self, validator_mock,
                                              requests_mock):
        content = self.file_content('mozball.owa')
        response_mock = mock.Mock(status_code=200)
        response_mock.iter_content.return_value = mock.Mock(
            next=lambda: content)
        response_mock.headers = {'content-type': self.content_type}
        yield response_mock
        requests_mock.return_value = response_mock

        validator_mock.return_value = json.dumps(self.validation_ok())
        self.upload_file('mozball.owa')
        upload = FileUpload.objects.get()
        tasks.fetch_manifest('http://xx.com/manifest.owa', upload.pk)

        r = self.client.get(reverse('mkt.developers.upload_detail',
                                    args=[upload.uuid, 'json']))
        data = json.loads(r.content)
        eq_(data['validation']['messages'], [])  # no errors
        assert_no_validation_errors(data)  # no exception
        eq_(r.status_code, 200)
        eq_(data['url'],
            reverse('mkt.developers.upload_detail', args=[upload.uuid,
                                                          'json']))
        eq_(data['full_report_url'],
            reverse('mkt.developers.upload_detail', args=[upload.uuid]))
Пример #9
0
    def create(self, request, *args, **kwargs):
        """
        Custom create method allowing us to re-use form logic and distinguish
        packaged app from hosted apps, applying delays to the validation task
        if necessary.

        Doesn't rely on any serializer, just forms.
        """
        data = self.request.data
        packaged = 'upload' in data
        form = (NewPackagedForm(data) if packaged
                else NewManifestForm(data))

        if not form.is_valid():
            return Response(form.errors, status=HTTP_400_BAD_REQUEST)

        if not packaged:
            upload = FileUpload.objects.create(
                user=request.user if request.user.is_authenticated() else None)
            # The hosted app validator is pretty fast.
            tasks.fetch_manifest(form.cleaned_data['manifest'], upload.pk)
        else:
            upload = form.file_upload
            # The packaged app validator is much heavier.
            tasks.validator.delay(upload.pk)

        log.info('Validation created: %s' % upload.pk)
        self.kwargs = {'pk': upload.pk}
        # Re-fetch the object, fetch_manifest() might have altered it.
        upload = self.get_object()
        serializer = self.get_serializer(upload)
        status = HTTP_201_CREATED if upload.processed else HTTP_202_ACCEPTED
        return Response(serializer.data, status=status)
Пример #10
0
 def test_url_timeout(self):
     reason = socket.timeout('too slow')
     self.requests_mock.side_effect = RequestException(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and try '
         'again.')
Пример #11
0
 def test_connection_error(self):
     reason = socket.gaierror(8, 'nodename nor servname provided')
     self.urlopen_mock.side_effect = urllib2.URLError(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and try '
         'again.')
Пример #12
0
    def test_response_too_large(self):
        with self.patch_urlopen() as ur:
            content = 'x' * (settings.MAX_WEBAPP_UPLOAD_SIZE + 1)
            ur.read.return_value = content

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation('Your manifest must be less than 2097152 bytes.')
Пример #13
0
 def test_url_timeout(self):
     reason = socket.timeout('too slow')
     self.urlopen_mock.side_effect = urllib2.URLError(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and try '
         'again.')
Пример #14
0
 def test_other_url_error(self):
     reason = Exception('Some other failure.')
     self.urlopen_mock.side_effect = urllib2.URLError(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and try '
         'again.')
Пример #15
0
    def test_success_call_validator(self, validator_mock):
        with self.patch_urlopen() as ur:
            ct = self.content_type + '; charset=utf-8'
            ur.headers = {'Content-Type': ct}

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        assert validator_mock.called
Пример #16
0
 def test_http_error(self):
     self.urlopen_mock.side_effect = urllib2.HTTPError(
         'url', 404, 'Not Found', [], None)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and try '
         'again.')
Пример #17
0
    def test_response_too_large(self):
        with self.patch_requests() as ur:
            content = "x" * (settings.MAX_WEBAPP_UPLOAD_SIZE + 1)
            ur.iter_content.return_value = mock.Mock(next=lambda: content)

        tasks.fetch_manifest("url", self.upload.pk)
        max_webapp_size = settings.MAX_WEBAPP_UPLOAD_SIZE
        self.check_validation("Your manifest must be less than %s bytes." % max_webapp_size)
Пример #18
0
 def test_other_url_error(self):
     reason = Exception('Some other failure.')
     self.urlopen_mock.side_effect = urllib2.URLError(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and make'
         ' sure the manifest is served with the HTTP header '
         '"Content-Type: application/x-web-app-manifest+json".')
Пример #19
0
 def test_other_url_error(self):
     reason = Exception('Some other failure.')
     self.urlopen_mock.side_effect = urllib2.URLError(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and make'
         ' sure the manifest is served with the HTTP header '
         '"Content-Type: application/x-web-app-manifest+json".')
Пример #20
0
 def test_connection_error(self):
     reason = socket.gaierror(8, 'nodename nor servname provided')
     self.urlopen_mock.side_effect = urllib2.URLError(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and make'
         ' sure the manifest is served with the HTTP header '
         '"Content-Type: application/x-web-app-manifest+json".')
Пример #21
0
    def test_bad_content_type(self):
        with self.patch_urlopen() as ur:
            ur.headers = {'Content-Type': 'x'}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'Your manifest must be served with the HTTP header '
            '"Content-Type: application/x-web-app-manifest+json". We saw "x".')
Пример #22
0
 def test_non_utf8_encoding(self):
     with self.patch_requests() as ur:
         with open(self.file("utf8bom.webapp")) as fp:
             # Set encoding to utf16 which will be invalid.
             content = fp.read().decode("utf8").encode("utf16")
             ur.iter_content.return_value = mock.Mock(next=lambda: content)
     tasks.fetch_manifest("url", self.upload.pk)
     self.check_validation("Your manifest file was not encoded as valid UTF-8.")
Пример #23
0
    def test_no_content_type(self):
        with self.patch_requests() as ur:
            ur.headers = {}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'No manifest was found at that URL. Check the address and try '
            'again.')
Пример #24
0
    def test_success_add_file(self, validator_mock):
        with self.patch_requests() as ur:
            ur.iter_content.return_value = mock.Mock(next=lambda: 'woo')

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        upload = FileUpload.objects.get(pk=self.upload.pk)
        eq_(upload.name, 'http://xx.com/manifest.json')
        eq_(private_storage.open(upload.path).read(), 'woo')
Пример #25
0
    def test_bad_content_type(self):
        with self.patch_urlopen() as ur:
            ur.headers = {'Content-Type': 'x'}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'Your manifest must be served with the HTTP header '
            '"Content-Type: application/x-web-app-manifest+json". We saw "x".')
Пример #26
0
    def test_success_add_file(self, validator_mock):
        with self.patch_requests() as ur:
            ur.iter_content.return_value = mock.Mock(next=lambda: 'woo')

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        upload = FileUpload.objects.get(pk=self.upload.pk)
        eq_(upload.name, 'http://xx.com/manifest.json')
        eq_(storage.open(upload.path).read(), 'woo')
Пример #27
0
 def test_http_error(self):
     self.urlopen_mock.side_effect = urllib2.HTTPError(
         'url', 404, 'Not Found', [], None)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and make'
         ' sure the manifest is served with the HTTP header '
         '"Content-Type: application/x-web-app-manifest+json".')
Пример #28
0
    def test_bad_charset(self):
        with self.patch_requests() as ur:
            ur.headers = {"content-type": "application/x-web-app-manifest+json;" "charset=ISO-1234567890-LOL"}

        tasks.fetch_manifest("url", self.upload.pk)
        self.check_validation(
            "The manifest's encoding does not match the " "charset provided in the HTTP Content-Type."
        )
Пример #29
0
 def test_non_utf8_encoding(self):
     with self.patch_urlopen() as ur:
         with open(self.file('utf8bom.webapp')) as fp:
             # Set encoding to utf16 which will be invalid
             ur.read.return_value = fp.read().decode('utf8').encode('utf16')
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'Your manifest file was not encoded as valid UTF-8')
Пример #30
0
 def test_http_error(self):
     self.urlopen_mock.side_effect = urllib2.HTTPError(
         'url', 404, 'Not Found', [], None)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and make'
         ' sure the manifest is served with the HTTP header '
         '"Content-Type: application/x-web-app-manifest+json".')
Пример #31
0
 def test_non_utf8_encoding(self):
     with self.patch_urlopen() as ur:
         with open(self.file('utf8bom.webapp')) as fp:
             # Set encoding to utf16 which will be invalid
             ur.read.return_value = fp.read().decode('utf8').encode('utf16')
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
                 'Your manifest file was not encoded as valid UTF-8.')
Пример #32
0
 def test_connection_error(self):
     reason = socket.gaierror(8, 'nodename nor servname provided')
     self.urlopen_mock.side_effect = urllib2.URLError(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'No manifest was found at that URL. Check the address and make'
         ' sure the manifest is served with the HTTP header '
         '"Content-Type: application/x-web-app-manifest+json".')
Пример #33
0
    def test_good_charset(self):
        with self.patch_urlopen() as ur:
            ur.headers = {
                'Content-Type': 'application/x-web-app-manifest+json;'
                                'charset=utf-8'}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation()
Пример #34
0
    def test_http_error(self):
        with self.patch_requests() as ur:
            ur.status_code = 404

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'No manifest was found at that URL. Check the address and try '
            'again.')
Пример #35
0
    def test_http_error(self):
        with self.patch_requests() as ur:
            ur.status_code = 404

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'No manifest was found at that URL. Check the address and try '
            'again.')
Пример #36
0
    def test_no_content_type(self):
        with self.patch_requests() as ur:
            ur.headers = {}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'No manifest was found at that URL. Check the address and try '
            'again.')
Пример #37
0
    def test_bad_content_type(self):
        with self.patch_urlopen() as ur:
            ur.headers = {'Content-Type': 'x'}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'Manifests must be served with the HTTP header "Content-Type: '
            'application/x-web-app-manifest+json". See %s for more '
            'information.' % tasks.CT_URL)
Пример #38
0
    def test_success_add_file(self, validator_mock):
        with self.patch_urlopen() as ur:
            ur.read.return_value = 'woo'

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        upload = FileUpload.objects.get(pk=self.upload.pk)
        eq_(upload.name, 'http://xx.com/manifest.json')
        eq_(upload.is_webapp, True)
        eq_(storage.open(upload.path).read(), 'woo')
Пример #39
0
    def test_bad_content_type(self):
        with self.patch_urlopen() as ur:
            ur.headers = {'Content-Type': 'x'}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'No manifest was found at that URL. Check the address and make'
            ' sure the manifest is served with the HTTP header '
            '"Content-Type: application/x-web-app-manifest+json".')
Пример #40
0
    def obj_create(self, bundle, request=None, **kwargs):
        form = NewManifestForm(bundle.data)
        if not form.is_valid():
            raise self.form_errors(form)

        bundle.obj = FileUpload.objects.create(user=amo.get_user())
        tasks.fetch_manifest(form.cleaned_data['manifest'], bundle.obj.pk)
        log.info('Validation created: %s' % bundle.obj.pk)
        return bundle
Пример #41
0
    def test_bad_charset(self):
        with self.patch_urlopen() as ur:
            ur.headers = {
                'Content-Type': 'application/x-web-app-manifest+json;'
                                'charset=ISO-1234567890-LOL'}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation("The manifest's encoding does not match the "
                              'charset provided in the HTTP Content-Type.')
Пример #42
0
    def obj_create(self, bundle, request=None, **kwargs):
        form = NewManifestForm(bundle.data)
        if not form.is_valid():
            raise self.form_errors(form)

        bundle.obj = FileUpload.objects.create()
        tasks.fetch_manifest(form.cleaned_data['manifest'], bundle.obj.pk)
        log.info('Validation created: %s' % bundle.obj.pk)
        return bundle
Пример #43
0
    def test_bad_content_type(self):
        with self.patch_urlopen() as ur:
            ur.headers = {'Content-Type': 'x'}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'No manifest was found at that URL. Check the address and make'
            ' sure the manifest is served with the HTTP header '
            '"Content-Type: application/x-web-app-manifest+json".')
Пример #44
0
    def test_good_charset(self):
        with self.patch_requests() as ur:
            ur.headers = {
                'content-type': 'application/x-web-app-manifest+json;'
                                'charset=utf-8'
            }

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation()
Пример #45
0
    def test_success_call_validator(self, validator_mock):
        with self.patch_requests() as ur:
            ct = self.content_type + '; charset=utf-8'
            ur.headers = {'content-type': ct}

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        assert validator_mock.called
        assert self.requests_mock.called
        eq_(self.requests_mock.call_args[1]['headers'], tasks.REQUESTS_HEADERS)
Пример #46
0
 def test_non_utf8_encoding(self):
     with self.patch_requests() as ur:
         with open(self.file('utf8bom.webapp')) as fp:
             # Set encoding to utf16 which will be invalid.
             content = fp.read().decode('utf8').encode('utf16')
             ur.iter_content.return_value = mock.Mock(next=lambda: content)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation(
         'Your manifest file was not encoded as valid UTF-8.')
Пример #47
0
    def test_bad_content_type(self):
        with self.patch_requests() as ur:
            ur.headers = {'Content-Type': 'x'}

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation(
            'Manifests must be served with the HTTP header "Content-Type: '
            'application/x-web-app-manifest+json". See %s for more '
            'information.' % tasks.CT_URL)
Пример #48
0
    def test_response_too_large(self):
        with self.patch_requests() as ur:
            content = 'x' * (settings.MAX_WEBAPP_UPLOAD_SIZE + 1)
            ur.iter_content.return_value = mock.Mock(next=lambda: content)

        tasks.fetch_manifest('url', self.upload.pk)
        max_webapp_size = settings.MAX_WEBAPP_UPLOAD_SIZE
        self.check_validation('Your manifest must be less than %s bytes.' %
                              max_webapp_size)
Пример #49
0
    def test_success_call_validator(self, validator_mock):
        with self.patch_requests() as ur:
            ct = self.content_type + '; charset=utf-8'
            ur.headers = {'content-type': ct}

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        assert validator_mock.called
        assert self.requests_mock.called
        eq_(self.requests_mock.call_args[1]['headers'], tasks.REQUESTS_HEADERS)
Пример #50
0
    def test_bad_content_type(self):
        with self.patch_requests() as ur:
            ur.headers = {"Content-Type": "x"}

        tasks.fetch_manifest("url", self.upload.pk)
        self.check_validation(
            'Manifests must be served with the HTTP header "Content-Type: '
            'application/x-web-app-manifest+json". See %s for more '
            "information." % tasks.CT_URL
        )
Пример #51
0
    def test_success_add_file(self, validator_mock):
        with self.patch_urlopen() as ur:
            ur.read.return_value = 'woo'
            ur.headers = {'Content-Type': self.content_type}

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        upload = FileUpload.objects.get(pk=self.upload.pk)
        eq_(upload.name, 'http://xx.com/manifest.json')
        eq_(upload.is_webapp, True)
        eq_(storage.open(upload.path).read(), 'woo')
Пример #52
0
    def test_bad_charset(self):
        with self.patch_requests() as ur:
            ur.headers = {
                'content-type': 'application/x-web-app-manifest+json;'
                                'charset=ISO-1234567890-LOL'
            }

        tasks.fetch_manifest('url', self.upload.pk)
        self.check_validation("The manifest's encoding does not match the "
                              'charset provided in the HTTP Content-Type.')
Пример #53
0
    def test_strip_utf8_bom(self):
        with self.patch_urlopen() as ur:
            with open(self.file('utf8bom.webapp')) as fp:
                ur.read.return_value = fp.read()

        tasks.fetch_manifest('url', self.upload.pk)
        upload = self.get_upload()
        with storage.open(upload.path, 'rb') as fp:
            manifest = fp.read()
            json.loads(manifest)  # no parse error
            assert not manifest.startswith(codecs.BOM_UTF8)
Пример #54
0
    def test_strip_utf8_bom(self):
        with self.patch_urlopen() as ur:
            with open(self.file('utf8bom.webapp')) as fp:
                ur.read.return_value = fp.read()

        tasks.fetch_manifest('url', self.upload.pk)
        upload = self.get_upload()
        with storage.open(upload.path, 'rb') as fp:
            manifest = fp.read()
            json.loads(manifest)  # no parse error
            assert not manifest.startswith(codecs.BOM_UTF8)
Пример #55
0
    def test_strip_utf8_bom(self):
        with self.patch_requests() as ur:
            with open(self.file('utf8bom.webapp')) as fp:
                content = fp.read()
                ur.iter_content.return_value = mock.Mock(next=lambda: content)

        tasks.fetch_manifest('url', self.upload.pk)
        upload = self.get_upload()
        with storage.open(upload.path, 'rb') as fp:
            manifest = fp.read()
            json.loads(manifest)  # No parse error.
            assert not manifest.startswith(codecs.BOM_UTF8)
Пример #56
0
    def test_strip_utf8_bom(self):
        with self.patch_requests() as ur:
            with open(self.file('utf8bom.webapp')) as fp:
                content = fp.read()
                ur.iter_content.return_value = mock.Mock(next=lambda: content)

        tasks.fetch_manifest('url', self.upload.pk)

        # Should not be called with anything else (e.g., `decode_unicode`).
        ur.iter_content.assert_called_with(
            chunk_size=settings.MAX_WEBAPP_UPLOAD_SIZE + 1)

        upload = self.get_upload()
        with private_storage.open(upload.path, 'rb') as fp:
            manifest = fp.read()
            json.loads(manifest)  # No parse error.
            assert not manifest.startswith(codecs.BOM_UTF8)
Пример #57
0
    def test_detail_for_free_extension_webapp(self, validator_mock,
                                              urlopen_mock):
        rs = mock.Mock()
        rs.read.return_value = self.file_content('mozball.owa')
        rs.headers = {'Content-Type': 'application/x-web-app-manifest+json'}
        urlopen_mock.return_value = rs
        validator_mock.return_value = json.dumps(self.validation_ok())
        self.upload_file('mozball.owa')
        upload = FileUpload.objects.get()
        tasks.fetch_manifest('http://xx.com/manifest.owa', upload.pk)

        r = self.client.get(reverse('mkt.developers.upload_detail',
                                    args=[upload.uuid, 'json']))
        data = json.loads(r.content)
        eq_(data['validation']['messages'], [])  # no errors
        assert_no_validation_errors(data)  # no exception
        eq_(r.status_code, 200)
        eq_(data['url'],
            reverse('mkt.developers.upload_detail', args=[upload.uuid,
                                                          'json']))
        eq_(data['full_report_url'],
            reverse('mkt.developers.upload_detail', args=[upload.uuid]))
Пример #58
0
    def obj_create(self, bundle, request=None, **kwargs):
        packaged = 'upload' in bundle.data
        form = (NewPackagedForm(bundle.data) if packaged
                else NewManifestForm(bundle.data))

        if not form.is_valid():
            raise self.form_errors(form)

        if not packaged:
            upload = FileUpload.objects.create(
                user=getattr(request, 'amo_user', None))
            # The hosted app validator is pretty fast.
            tasks.fetch_manifest(form.cleaned_data['manifest'], upload.pk)
        else:
            upload = form.file_upload
            # The packaged app validator is much heavier.
            tasks.validator.delay(upload.pk)

        # This is a reget of the object, we do this to get the refreshed
        # results if not celery delayed.
        bundle.obj = FileUpload.uncached.get(pk=upload.pk)
        log.info('Validation created: %s' % bundle.obj.pk)
        return bundle
Пример #59
0
 def test_other_url_error(self):
     reason = Exception('Some other failure.')
     self.urlopen_mock.side_effect = urllib2.URLError(reason)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation('Some other failure.')
Пример #60
0
 def test_http_error(self):
     self.urlopen_mock.side_effect = urllib2.HTTPError(
         'url', 404, 'Not Found', [], None)
     tasks.fetch_manifest('url', self.upload.pk)
     self.check_validation('url responded with 404 (Not Found).')