api: add dedicated error handling for invalid place count value (#19552)

This commit is contained in:
Frédéric Péters 2017-10-19 13:21:06 +02:00
parent fc1bdf3391
commit 6ead030aed
2 changed files with 11 additions and 1 deletions

View File

@ -312,7 +312,13 @@ class Fillslot(GenericAPIView):
raise Http404()
if 'count' in request.GET:
places_count = int(request.GET['count'])
try:
places_count = int(request.GET['count'])
except ValueError:
return Response({
'err': 1,
'reason': 'invalid value for count (%r)' % request.GET['count'],
})
else:
places_count = 1

View File

@ -616,6 +616,10 @@ def test_multiple_booking_api(app, some_data, user):
event_fillslot_url = [x for x in resp_datetimes.json['data'] if x['id'] == event.id][0]['api']['fillslot_url']
app.authorization = ('Basic', ('john.doe', 'password'))
resp = app.post('/api/agenda/%s/fillslot/%s/?count=NaN' % (agenda.slug, event.id))
assert resp.json['err'] == 1
assert resp.json['reason'] == "invalid value for count (u'NaN')"
resp = app.post('/api/agenda/%s/fillslot/%s/?count=3' % (agenda.slug, event.id))
Booking.objects.get(id=resp.json['booking_id'])
assert resp.json['datetime'] == localtime(event.start_datetime).isoformat()