add FileValidation to remember validation results (bug 618997)

This commit is contained in:
Jeff Balogh 2010-12-14 09:41:36 -08:00
Родитель 91c1c62eb4
Коммит f4aec1758c
4 изменённых файлов: 52 добавлений и 4 удалений

Просмотреть файл

@ -3036,10 +3036,11 @@ class UploadTest(files.tests.UploadTest, test_utils.TestCase):
def setUp(self):
super(UploadTest, self).setUp()
v = json.dumps(dict(errors=0, warnings=1, notices=2))
xpi = open(self.xpi_path('extension')).read()
self.upload = FileUpload.from_post([xpi], filename='extension.xpi',
size=1234)
self.upload.update(valid=True)
self.upload.update(valid=True, validation=v)
self.addon = Addon.objects.get(id=3615)
self.version = self.addon.current_version
self.addon.update(guid='guid@xpi')
@ -3136,9 +3137,10 @@ class TestCreateAddon(files.tests.UploadTest, test_utils.TestCase):
super(TestCreateAddon, self).setUp()
self._redis = mock_redis()
xpi = open(self.xpi_path('extension')).read()
v = json.dumps(dict(errors=0, warnings=1, notices=2))
self.upload = FileUpload.from_post([xpi], filename='extension.xpi',
size=1234)
self.upload.update(valid=True)
self.upload.update(valid=True, validation=v)
self.url = reverse('devhub.submit.2')
assert self.client.login(username='regular@mozilla.com',
password='password')

Просмотреть файл

@ -96,6 +96,7 @@ class File(amo.models.ModelBase):
if not dest.exists():
dest.makedirs()
upload.path.rename(dest / f.filename)
FileValidation.from_json(f, upload.validation)
return f
@classmethod
@ -255,6 +256,27 @@ class FileUpload(amo.models.ModelBase):
hash='sha256:%s' % hash.hexdigest())
class FileValidation(amo.models.ModelBase):
file = models.ForeignKey(File)
valid = models.BooleanField(default=False)
errors = models.IntegerField(default=0)
warnings = models.IntegerField(default=0)
notices = models.IntegerField(default=0)
validation = models.TextField()
class Meta:
db_table = 'file_validation'
@classmethod
def from_json(cls, file, validation):
js = json.loads(validation)
new = cls(file=file, validation=validation, errors=js['errors'],
warnings=js['warnings'], notices=js['notices'])
new.valid = new.errors == 0
new.save()
return new
class TestCase(amo.models.ModelBase):
test_group = models.ForeignKey('TestGroup')
help_link = models.CharField(max_length=255, blank=True,

Просмотреть файл

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import hashlib
import json
import os
import shutil
import tempfile
@ -17,7 +18,7 @@ from nose.tools import eq_
import amo.utils
from addons.models import Addon
from applications.models import Application, AppVersion
from files.models import File, FileUpload, Platform
from files.models import File, FileUpload, FileValidation, Platform
from files.utils import parse_xpi, parse_search, parse_addon
from versions.models import Version
@ -315,8 +316,9 @@ class TestFileFromUpload(UploadTest):
self.version = Version.objects.create(addon=self.addon)
def upload(self, name):
v = json.dumps(dict(errors=0, warnings=1, notices=2))
d = dict(path=self.xpi_path(name), name='%s.xpi' % name,
hash='sha256:%s' % name)
hash='sha256:%s' % name, validation=v)
return FileUpload.objects.create(**d)
def test_is_jetpack(self):
@ -329,6 +331,16 @@ class TestFileFromUpload(UploadTest):
f = File.from_upload(upload, self.version, self.platform)
eq_(f.filename, 'xxx-0.1-mac.xpi')
def test_file_validation(self):
upload = self.upload('jetpack')
file = File.from_upload(upload, self.version, self.platform)
fv = FileValidation.objects.get(file=file)
eq_(fv.validation, upload.validation)
eq_(fv.valid, True)
eq_(fv.errors, 0)
eq_(fv.warnings, 1)
eq_(fv.notices, 2)
class TestZip(test_utils.TestCase):

Просмотреть файл

@ -0,0 +1,12 @@
CREATE TABLE `file_validation` (
`id` int(11) unsigned AUTO_INCREMENT NOT NULL PRIMARY KEY,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
`file_id` integer NOT NULL,
`valid` bool NOT NULL,
`errors` integer NOT NULL,
`warnings` integer NOT NULL,
`notices` integer NOT NULL,
`validation` longtext NOT NULL
);
ALTER TABLE `file_validation` ADD CONSTRAINT FOREIGN KEY (`file_id`) REFERENCES `files` (`id`);