示例#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
文件: test_tasks.py 项目: vdt/zamboni
    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
文件: test_tasks.py 项目: vdt/zamboni
 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
文件: test_tasks.py 项目: vdt/zamboni
 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).')