1339 |
1339 |
assert Event.objects.get(id=event.id).booked_places == 3
|
1340 |
1340 |
assert Event.objects.get(id=event.id).waiting_list == 2
|
1341 |
1341 |
|
|
1342 |
|
|
1343 |
def test_multiple_booking_move_booking(app, user):
|
|
1344 |
agenda = Agenda(label=u'Foo bar')
|
|
1345 |
agenda.save()
|
|
1346 |
first_date = localtime(now()).replace(hour=17, minute=0, second=0, microsecond=0)
|
|
1347 |
first_date += datetime.timedelta(days=1)
|
|
1348 |
events = []
|
|
1349 |
for i in range(10):
|
|
1350 |
event = Event(
|
|
1351 |
start_datetime=first_date + datetime.timedelta(days=i),
|
|
1352 |
places=20, agenda=agenda
|
|
1353 |
)
|
|
1354 |
event.save()
|
|
1355 |
events.append(event)
|
|
1356 |
|
|
1357 |
first_two_events = events[:2]
|
|
1358 |
events_ids = [x.id for x in first_two_events]
|
|
1359 |
resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda.id)
|
|
1360 |
slots = [x['id'] for x in resp_datetimes.json['data'] if x['id'] in events_ids]
|
|
1361 |
|
|
1362 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
1363 |
|
|
1364 |
# get 1 place on 2 slots
|
|
1365 |
resp = app.post('/api/agenda/%s/fillslots/' % agenda.slug, params={'slots': slots})
|
|
1366 |
booking = Booking.objects.get(id=resp.json['booking_id'])
|
|
1367 |
assert Booking.objects.filter(primary_booking=booking).count() == 1
|
|
1368 |
for event in first_two_events:
|
|
1369 |
assert Event.objects.get(id=event.id).booked_places == 1
|
|
1370 |
|
|
1371 |
# change, 1 place on 2 other slots
|
|
1372 |
last_two_events = events[-2:]
|
|
1373 |
events_ids = [x.id for x in last_two_events]
|
|
1374 |
resp_datetimes = app.get('/api/agenda/%s/datetimes/' % agenda.id)
|
|
1375 |
slots = [x['id'] for x in resp_datetimes.json['data'] if x['id'] in events_ids]
|
|
1376 |
|
|
1377 |
resp = app.post(
|
|
1378 |
'/api/agenda/%s/fillslots/' % agenda.slug,
|
|
1379 |
params={'slots': slots, 'cancel_booking_id': booking.pk}
|
|
1380 |
)
|
|
1381 |
booking = Booking.objects.get(id=resp.json['booking_id'])
|
|
1382 |
assert Booking.objects.filter(primary_booking=booking).count() == 1
|
|
1383 |
for event in first_two_events:
|
|
1384 |
assert Event.objects.get(id=event.id).booked_places == 0
|
|
1385 |
for event in last_two_events:
|
|
1386 |
assert Event.objects.get(id=event.id).booked_places == 1
|
|
1387 |
|
|
1388 |
|
1342 |
1389 |
def test_agenda_detail_api(app, some_data):
|
1343 |
1390 |
agenda = Agenda.objects.get(slug='foo-bar')
|
1344 |
1391 |
resp = app.get('/api/agenda/%s/' % agenda.slug)
|
1345 |
|
-
|