wcs: raise a bad request when tracking code is missing from request (#33079)

This commit is contained in:
Frédéric Péters 2019-06-02 18:11:10 +02:00
parent 0863f0fa7a
commit 6439c43b48
2 changed files with 5 additions and 0 deletions

View File

@ -60,6 +60,8 @@ class TrackingCodeView(View):
cell = TrackingCodeInputCell.objects.get(id=request.POST['cell']) cell = TrackingCodeInputCell.objects.get(id=request.POST['cell'])
except (KeyError, ValueError, TrackingCodeInputCell.DoesNotExist): except (KeyError, ValueError, TrackingCodeInputCell.DoesNotExist):
return HttpResponseBadRequest('Invalid cell id') return HttpResponseBadRequest('Invalid cell id')
if not 'code' in request.POST:
return HttpResponseBadRequest('Missing code')
code = request.POST['code'] code = request.POST['code']
url = self.search(code, wcs_site=cell.wcs_site) url = self.search(code, wcs_site=cell.wcs_site)

View File

@ -14,6 +14,7 @@ import os
from django.apps import apps from django.apps import apps
from django.conf import settings from django.conf import settings
from django.core.cache import cache from django.core.cache import cache
from django.core.urlresolvers import reverse
from django.test import override_settings from django.test import override_settings
from django.test.client import RequestFactory from django.test.client import RequestFactory
from django.utils.six.moves.urllib import parse as urlparse from django.utils.six.moves.urllib import parse as urlparse
@ -668,6 +669,8 @@ def test_tracking_code_cell(app):
resp.form['code'] = 'CNPHNTFB' resp.form['code'] = 'CNPHNTFB'
resp = resp.form.submit(status=400) resp = resp.form.submit(status=400)
resp = app.post(reverse('wcs-tracking-code'), params={'cell': cell.id}, status=400)
@wcsctl_present @wcsctl_present
def test_cell_assets(app, admin_user): def test_cell_assets(app, admin_user):
page = Page(title='xxx', slug='test_cell_assets', template_name='standard') page = Page(title='xxx', slug='test_cell_assets', template_name='standard')