provide a mock sign for anyone who might hit sign

This commit is contained in:
Andy McKay 2012-09-26 14:29:02 -07:00
Родитель 1ec76db309
Коммит 71ed3e4bf4
4 изменённых файлов: 30 добавлений и 0 удалений

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

@ -15,6 +15,25 @@ from files.utils import SafeUnzip
from lib.crypto import packaged
from lib.crypto.receipt import crack, sign, SigningError
from mkt.webapps.models import Webapp
from versions.models import Version
def mock_sign(version_id, reviewer=False):
"""
This is a mock for using in tests, where we really don't want to be
actually signing the apps. This just copies the file over and returns
the path. It doesn't have much error checking.
"""
version = Version.objects.get(pk=version_id)
file_obj = version.all_files[0]
path = (file_obj.signed_reviewer_file_path if reviewer else
file_obj.signed_file_path)
try:
os.makedirs(os.path.dirname(path))
except OSError:
pass
shutil.copyfile(file_obj.file_path, path)
return path
@mock.patch('lib.metrics.urllib2.urlopen')

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

@ -5,6 +5,8 @@ from django.conf import settings
import amo
from amo.urlresolvers import reverse
from lib.crypto import packaged
from lib.crypto.tests import mock_sign
from mkt.submit.tests.test_views import BasePackagedAppTest
from mkt.webapps.models import Webapp
@ -18,6 +20,7 @@ class TestDownload(BasePackagedAppTest):
super(TestDownload, self).setup_files()
self.url = reverse('downloads.file', args=[self.file.pk])
@mock.patch.object(packaged, 'sign', mock_sign)
def test_download(self):
res = self.client.get(self.url)
eq_(res.status_code, 200)
@ -27,11 +30,13 @@ class TestDownload(BasePackagedAppTest):
self.app.update(status=amo.STATUS_DISABLED)
eq_(self.client.get(self.url).status_code, 404)
@mock.patch.object(packaged, 'sign', mock_sign)
def test_disabled_but_owner(self):
self.client.login(username='steamcube@mozilla.com',
password='password')
eq_(self.client.get(self.url).status_code, 200)
@mock.patch.object(packaged, 'sign', mock_sign)
def test_disabled_but_admin(self):
self.client.login(username='admin@mozilla.com',
password='password')

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

@ -27,6 +27,8 @@ from devhub.models import ActivityLog, AppLog
from editors.models import (CannedResponse, EscalationQueue, RereviewQueue,
ReviewerScore)
from files.models import File
from lib.crypto import packaged
from lib.crypto.tests import mock_sign
import mkt.constants.reviewers as rvw
from mkt.reviewers.models import ThemeLock
from mkt.submit.tests.test_views import BasePackagedAppTest
@ -1824,6 +1826,7 @@ class TestGetSigned(BasePackagedAppTest, amo.tests.TestCase):
self.client.login(username='regular@mozilla.com', password='password')
eq_(self.client.get(self.url).status_code, 403)
@mock.patch.object(packaged, 'sign', mock_sign)
def test_reviewer(self):
self.setup_files()
res = self.client.get(self.url)

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

@ -18,6 +18,8 @@ from amo.tests import (app_factory, ESTestCase, TestCase, version_factory,
from constants.applications import DEVICE_TYPES
from editors.models import RereviewQueue
from files.models import File
from lib.crypto import packaged
from lib.crypto.tests import mock_sign
from market.models import Price
from users.models import UserProfile
from versions.models import Version
@ -426,6 +428,7 @@ class TestPackagedManifest(BasePackagedAppTest):
eq_(data['icons'], manifest['icons'])
eq_(data['locales'], manifest['locales'])
@mock.patch.object(packaged, 'sign', mock_sign)
def test_package_path(self):
webapp = self.post_addon()
version = webapp.current_version