api: return an error when number of requested places is <= 0 (#31047)
This commit is contained in:
parent
b9a2848a26
commit
cd36887df6
|
@ -370,6 +370,12 @@ class Fillslots(APIView):
|
|||
else:
|
||||
places_count = 1
|
||||
|
||||
if places_count <= 0:
|
||||
return Response({
|
||||
'err': 1,
|
||||
'reason': 'count cannot be less than or equal to zero'
|
||||
}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
extra_data = {}
|
||||
for k, v in request.data.items():
|
||||
if k not in serializer.validated_data:
|
||||
|
|
|
@ -926,6 +926,16 @@ def test_multiple_booking_api(app, some_data, user):
|
|||
assert resp.json['err'] == 1
|
||||
assert resp.json['reason'] == "invalid value for count (NaN)"
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
resp = app.post('/api/agenda/%s/fillslot/%s/?count=0' % (agenda.slug, event.id), status=400)
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['reason'] == "count cannot be less than or equal to zero"
|
||||
|
||||
app.authorization = ('Basic', ('john.doe', 'password'))
|
||||
resp = app.post('/api/agenda/%s/fillslot/%s/?count=-3' % (agenda.slug, event.id), status=400)
|
||||
assert resp.json['err'] == 1
|
||||
assert resp.json['reason'] == "count cannot be less than or equal to zero"
|
||||
|
||||
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