return a 400 on a put
This commit is contained in:
Родитель
099e1dbf3a
Коммит
51a030066a
Двоичные данные
src/olympia/signing/fixtures/@create-webextension-invalid-version-1.0.xpi
Normal file
Двоичные данные
src/olympia/signing/fixtures/@create-webextension-invalid-version-1.0.xpi
Normal file
Двоичный файл не отображается.
|
@ -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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче