This commit is contained in:
Andy McKay 2016-07-19 16:12:24 -07:00
Родитель 099e1dbf3a
Коммит 51a030066a
3 изменённых файлов: 21 добавлений и 1 удалений

Двоичный файл не отображается.

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

@ -4,6 +4,7 @@ import json
from datetime import datetime, timedelta
from django.core.urlresolvers import reverse
from django.forms import ValidationError
from django.test.utils import override_settings
from django.utils import translation
@ -265,6 +266,23 @@ class TestUploadVersion(BaseUploadVersionCase):
assert version.is_beta
self.auto_sign_version.assert_called_with(version, is_beta=True)
def test_invalid_version_response_code(self):
# This raises an error in parse_addon which is not covered by
# an exception handler.
response = self.request(
'PUT',
self.url(self.guid, '1.0'),
addon='@create-webextension-invalid-version',
version='1.0')
assert response.status_code == 400
def test_raises_response_code(self):
# A check that any bare error in handle_upload will return a 400.
with mock.patch('olympia.signing.views.handle_upload') as patch:
patch.side_effect = ValidationError(message='some error')
response = self.request('PUT', self.url(self.guid, '1.0'))
assert response.status_code == 400
class TestUploadVersionWebextension(BaseUploadVersionCase):
def setUp(self):

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

@ -101,7 +101,9 @@ class VersionView(APIView):
file_upload, created = self.handle_upload(
request, addon, version_string)
except forms.ValidationError as exc:
return Response({'error': exc.message}, status=exc.code)
return Response(
{'error': exc.message},
status=exc.code or status.HTTP_400_BAD_REQUEST)
status_code = (
status.HTTP_201_CREATED if created else status.HTTP_202_ACCEPTED)