api: add dedicated error handling for invalid place count value (#19552)
This commit is contained in:
parent
fc1bdf3391
commit
6ead030aed
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue