本文整理汇总了Python中mkt.developers.tasks.fetch_manifest函数的典型用法代码示例。如果您正苦于以下问题:Python fetch_manifest函数的具体用法?Python fetch_manifest怎么用?Python fetch_manifest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fetch_manifest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_other_url_error
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.')
示例2: test_success_call_validator
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
示例3: test_connection_error
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.')
示例4: test_detail_for_free_extension_webapp
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]))
示例5: create
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)
示例6: test_http_error
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: test_url_timeout
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.')
示例8: test_success_call_validator
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
示例9: test_response_too_large
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.')
示例10: test_success_add_file
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')
示例11: test_http_error
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".')
示例12: test_response_too_large
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)
示例13: test_http_error
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.')
示例14: test_other_url_error
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".')
示例15: test_connection_error
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".')