1412 |
1412 |
assert primary.in_waiting_list is False
|
1413 |
1413 |
|
1414 |
1414 |
|
|
1415 |
def test_resize_booking(app, some_data, user):
|
|
1416 |
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
1417 |
event = Event.objects.filter(agenda_id=agenda_id).exclude(start_datetime__lt=now())[0]
|
|
1418 |
event.places = 5
|
|
1419 |
event.waiting_list_places = 5
|
|
1420 |
event.save()
|
|
1421 |
event2 = Event.objects.filter(agenda_id=agenda_id).exclude(start_datetime__lt=now())[1]
|
|
1422 |
|
|
1423 |
# create a booking not on the waiting list
|
|
1424 |
primary = Booking.objects.create(event=event, in_waiting_list=False)
|
|
1425 |
secondary = Booking.objects.create(event=event, in_waiting_list=False, primary_booking=primary)
|
|
1426 |
|
|
1427 |
assert Booking.objects.filter(in_waiting_list=False).count() == 2
|
|
1428 |
|
|
1429 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
1430 |
|
|
1431 |
resp = app.post('/api/booking/%s/resize/' % secondary.pk, params={'count': 42})
|
|
1432 |
assert resp.json['err'] == 2
|
|
1433 |
assert resp.json['reason'] == 'secondary booking' # legacy
|
|
1434 |
assert resp.json['err_class'] == 'secondary booking'
|
|
1435 |
assert resp.json['err_desc'] == 'secondary booking'
|
|
1436 |
|
|
1437 |
# resize a booking that doesn't exist
|
|
1438 |
resp = app.post('/api/booking/0/resize/', params={'count': 42}, status=404)
|
|
1439 |
|
|
1440 |
# decrease a booking to 0
|
|
1441 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 0}, status=400)
|
|
1442 |
assert resp.json['err'] == 1
|
|
1443 |
|
|
1444 |
# decrease a booking not in waiting list
|
|
1445 |
assert Booking.objects.filter(in_waiting_list=False).count() == 2
|
|
1446 |
assert Booking.objects.filter().count() == 2
|
|
1447 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 1})
|
|
1448 |
assert resp.json['err'] == 0
|
|
1449 |
assert Booking.objects.filter(in_waiting_list=False).count() == 1
|
|
1450 |
assert Booking.objects.filter(primary_booking__isnull=True).count() == 1
|
|
1451 |
assert Booking.objects.filter().count() == 1
|
|
1452 |
|
|
1453 |
# no changes
|
|
1454 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 1})
|
|
1455 |
assert resp.json['err'] == 0
|
|
1456 |
assert Booking.objects.filter(in_waiting_list=False).count() == 1
|
|
1457 |
assert Booking.objects.filter().count() == 1
|
|
1458 |
|
|
1459 |
# increase a booking not in waiting list
|
|
1460 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 2})
|
|
1461 |
assert resp.json['err'] == 0
|
|
1462 |
assert Booking.objects.filter(in_waiting_list=False).count() == 2
|
|
1463 |
assert Booking.objects.filter(primary_booking__isnull=True).count() == 1
|
|
1464 |
assert Booking.objects.filter().count() == 2
|
|
1465 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 6})
|
|
1466 |
assert resp.json['err'] == 3
|
|
1467 |
assert resp.json['reason'] == 'sold out' # legacy
|
|
1468 |
assert resp.json['err_class'] == 'sold out'
|
|
1469 |
assert resp.json['err_desc'] == 'sold out'
|
|
1470 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 5})
|
|
1471 |
assert resp.json['err'] == 0
|
|
1472 |
assert Booking.objects.filter(in_waiting_list=False).count() == 5
|
|
1473 |
assert Booking.objects.filter(primary_booking__isnull=True).count() == 1
|
|
1474 |
assert Booking.objects.filter().count() == 5
|
|
1475 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 6})
|
|
1476 |
assert resp.json['err'] == 3
|
|
1477 |
assert resp.json['reason'] == 'sold out' # legacy
|
|
1478 |
assert resp.json['err_class'] == 'sold out'
|
|
1479 |
assert resp.json['err_desc'] == 'sold out'
|
|
1480 |
|
|
1481 |
# decrease a booking in waiting list
|
|
1482 |
primary.suspend()
|
|
1483 |
assert Booking.objects.filter(in_waiting_list=True).count() == 5
|
|
1484 |
assert Booking.objects.filter().count() == 5
|
|
1485 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 1})
|
|
1486 |
assert resp.json['err'] == 0
|
|
1487 |
assert Booking.objects.filter(in_waiting_list=True).count() == 1
|
|
1488 |
assert Booking.objects.filter(primary_booking__isnull=True).count() == 1
|
|
1489 |
assert Booking.objects.filter().count() == 1
|
|
1490 |
|
|
1491 |
# no changes
|
|
1492 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 1})
|
|
1493 |
assert resp.json['err'] == 0
|
|
1494 |
assert Booking.objects.filter(in_waiting_list=True).count() == 1
|
|
1495 |
assert Booking.objects.filter().count() == 1
|
|
1496 |
|
|
1497 |
# increase a booking in waiting list
|
|
1498 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 2})
|
|
1499 |
assert resp.json['err'] == 0
|
|
1500 |
assert Booking.objects.filter(in_waiting_list=True).count() == 2
|
|
1501 |
assert Booking.objects.filter(primary_booking__isnull=True).count() == 1
|
|
1502 |
assert Booking.objects.filter().count() == 2
|
|
1503 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 6})
|
|
1504 |
assert resp.json['err'] == 3
|
|
1505 |
assert resp.json['reason'] == 'sold out' # legacy
|
|
1506 |
assert resp.json['err_class'] == 'sold out'
|
|
1507 |
assert resp.json['err_desc'] == 'sold out'
|
|
1508 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 5})
|
|
1509 |
assert resp.json['err'] == 0
|
|
1510 |
assert Booking.objects.filter(in_waiting_list=True).count() == 5
|
|
1511 |
assert Booking.objects.filter(primary_booking__isnull=True).count() == 1
|
|
1512 |
assert Booking.objects.filter().count() == 5
|
|
1513 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 6})
|
|
1514 |
assert resp.json['err'] == 3
|
|
1515 |
assert resp.json['reason'] == 'sold out' # legacy
|
|
1516 |
assert resp.json['err_class'] == 'sold out'
|
|
1517 |
assert resp.json['err_desc'] == 'sold out'
|
|
1518 |
|
|
1519 |
# resize a booking that is on multi events
|
|
1520 |
secondary = Booking.objects.create(event=event2, in_waiting_list=False, primary_booking=primary)
|
|
1521 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 42})
|
|
1522 |
assert resp.json['err'] == 4
|
|
1523 |
assert resp.json['reason'] == 'can not resize multi event booking' # legacy
|
|
1524 |
assert resp.json['err_class'] == 'can not resize multi event booking'
|
|
1525 |
assert resp.json['err_desc'] == 'can not resize multi event booking'
|
|
1526 |
# resize a booking that was cancelled before
|
|
1527 |
primary.cancel()
|
|
1528 |
resp = app.post('/api/booking/%s/resize/' % primary.pk, params={'count': 42})
|
|
1529 |
assert resp.json['err'] == 1
|
|
1530 |
|
|
1531 |
|
1415 |
1532 |
def test_multiple_booking_api(app, some_data, user):
|
1416 |
1533 |
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
|
1417 |
1534 |
event = [x for x in Event.objects.filter(agenda=agenda) if x.in_bookable_period()][0]
|
1418 |
|
-
|