Sets binary=True based on metadata in addon validation results (bug 649862)
This commit is contained in:
Родитель
b8312ee78d
Коммит
3d3cabe590
|
@ -2519,7 +2519,8 @@ class TestUploadDetail(BaseUploadTest):
|
|||
'notices': 0,
|
||||
'message_tree': {},
|
||||
'messages': [],
|
||||
'rejected': False}
|
||||
'rejected': False,
|
||||
'metadata': {}}
|
||||
|
||||
def upload_file(self, file):
|
||||
addon = os.path.join(settings.ROOT, 'apps', 'devhub', 'tests',
|
||||
|
|
|
@ -9,6 +9,7 @@ from nose.tools import eq_
|
|||
from pyquery import PyQuery as pq
|
||||
import test_utils
|
||||
|
||||
from addons.models import Addon
|
||||
from amo.tests import assert_no_validation_errors
|
||||
from amo.urlresolvers import reverse
|
||||
from files.models import File, FileUpload, FileValidation
|
||||
|
@ -174,3 +175,29 @@ class TestValidateFile(BaseUploadTest):
|
|||
assert data['error'].endswith(
|
||||
"ValueError: catastrophic failure in amo-validator\n"), (
|
||||
'Unexpected error: ...%s' % data['error'][-50:-1])
|
||||
|
||||
@mock.patch('devhub.tasks.run_validator')
|
||||
def test_validator_sets_binary_flag(self, v):
|
||||
v.return_value = json.dumps({
|
||||
"errors": 0,
|
||||
"success": True,
|
||||
"warnings": 0,
|
||||
"notices": 0,
|
||||
"message_tree": {},
|
||||
"messages": [],
|
||||
"metadata": {
|
||||
"contains_binary_extension": True,
|
||||
"version": "1.0",
|
||||
"name": "gK0Bes Bot",
|
||||
"id": "gkobes@gkobes"
|
||||
}
|
||||
})
|
||||
eq_(self.addon.binary, False)
|
||||
r = self.client.post(reverse('devhub.json_file_validation',
|
||||
args=[self.addon.slug, self.file.id]),
|
||||
follow=True)
|
||||
eq_(r.status_code, 200)
|
||||
data = json.loads(r.content)
|
||||
assert_no_validation_errors(data)
|
||||
addon = Addon.objects.get(pk=self.addon.id)
|
||||
eq_(addon.binary, True)
|
||||
|
|
|
@ -168,7 +168,8 @@ class File(amo.models.OnChangeMixin, amo.models.ModelBase):
|
|||
return self.filename
|
||||
if len(m.group('slug')) < maxlen:
|
||||
return self.filename
|
||||
return u'%s...%s' % (m.group('slug')[0:(maxlen-3)], m.group('suffix'))
|
||||
return u'%s...%s' % (m.group('slug')[0:(maxlen - 3)],
|
||||
m.group('suffix'))
|
||||
|
||||
def latest_xpi_url(self):
|
||||
addon = self.version.addon_id
|
||||
|
@ -390,6 +391,8 @@ class FileValidation(amo.models.ModelBase):
|
|||
new = cls(file=file, validation=validation, errors=js['errors'],
|
||||
warnings=js['warnings'], notices=js['notices'])
|
||||
new.valid = new.errors == 0
|
||||
if js['metadata'].get('contains_binary_extension', False):
|
||||
file.version.addon.update(binary=True)
|
||||
new.save()
|
||||
return new
|
||||
|
||||
|
|
|
@ -59,7 +59,8 @@ class UploadTest(test_utils.TestCase):
|
|||
xpi = open(self.file_path(filename)).read()
|
||||
upload = FileUpload.from_post([xpi], filename=filename, size=1234)
|
||||
upload.validation = (validation or
|
||||
json.dumps(dict(errors=0, warnings=1, notices=2)))
|
||||
json.dumps(dict(errors=0, warnings=1, notices=2,
|
||||
metadata={})))
|
||||
upload.save()
|
||||
return upload
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче