483 lines
20 KiB
Python
483 lines
20 KiB
Python
import datetime
|
|
import pytest
|
|
from webtest import TestApp
|
|
|
|
from django.contrib.auth import get_user_model
|
|
from django.test import override_settings
|
|
from django.utils.timezone import now, make_aware
|
|
|
|
from chrono.agendas.models import Agenda, Event, Booking, MeetingType, TimePeriod
|
|
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
@pytest.fixture
|
|
def user():
|
|
User = get_user_model()
|
|
user = User.objects.create(username='john.doe',
|
|
first_name=u'John', last_name=u'Doe', email='john.doe@example.net')
|
|
user.set_password('password')
|
|
user.save()
|
|
return user
|
|
|
|
@pytest.fixture
|
|
def some_data():
|
|
agenda = Agenda(label=u'Foo bar')
|
|
agenda.save()
|
|
first_date = datetime.datetime.now().replace(hour=17, minute=0, second=0)
|
|
first_date += datetime.timedelta(days=1)
|
|
for i in range(3):
|
|
event = Event(start_datetime=first_date + datetime.timedelta(days=i),
|
|
places=20, agenda=agenda)
|
|
event.save()
|
|
|
|
agenda2 = Agenda(label=u'Foo bar2')
|
|
agenda2.save()
|
|
first_date = datetime.datetime.now().replace(hour=20, minute=0, second=0)
|
|
first_date += datetime.timedelta(days=1)
|
|
for i in range(2):
|
|
event = Event(start_datetime=first_date + datetime.timedelta(days=i),
|
|
places=20, agenda=agenda2)
|
|
event.save()
|
|
|
|
# a date in the past
|
|
event = Event(start_datetime=first_date - datetime.timedelta(days=10),
|
|
places=10, agenda=agenda)
|
|
event.save()
|
|
|
|
@pytest.fixture
|
|
def meetings_agenda():
|
|
agenda = Agenda(label=u'Foo bar Meeting', kind='meetings',
|
|
minimal_booking_delay=1, maximal_booking_delay=56)
|
|
agenda.save()
|
|
meeting_type = MeetingType(agenda=agenda, label='Blah', duration=30)
|
|
meeting_type.save()
|
|
|
|
test_1st_weekday = (now().weekday() + 2) % 7
|
|
test_2nd_weekday = (now().weekday() + 3) % 7
|
|
|
|
time_period = TimePeriod(agenda=agenda, weekday=test_1st_weekday,
|
|
start_time=datetime.time(10, 0), end_time=datetime.time(12, 0))
|
|
time_period.save()
|
|
time_period = TimePeriod(agenda=agenda, weekday=test_2nd_weekday,
|
|
start_time=datetime.time(10, 0), end_time=datetime.time(17, 0))
|
|
time_period.save()
|
|
return agenda
|
|
|
|
def test_agendas_api(app, some_data):
|
|
agenda1 = Agenda.objects.filter(label=u'Foo bar')[0]
|
|
agenda2 = Agenda.objects.filter(label=u'Foo bar2')[0]
|
|
resp = app.get('/api/agenda/')
|
|
assert resp.json == {'data': [
|
|
{'text': 'Foo bar', 'id': agenda1.id, 'slug': u'foo-bar',
|
|
'api': {'datetimes': 'http://testserver/api/agenda/%s/datetimes/' % agenda1.slug}},
|
|
{'text': 'Foo bar2', 'id': agenda2.id, 'slug': u'foo-bar2',
|
|
'api': {'datetimes': 'http://testserver/api/agenda/%s/datetimes/' % agenda2.slug}}
|
|
]}
|
|
|
|
def test_datetimes_api(app, some_data):
|
|
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
|
|
|
|
def check_bookability(data):
|
|
for event in data:
|
|
assert Event.objects.get(id=event['id']).in_bookable_period()
|
|
for event in agenda.event_set.all():
|
|
if not event.in_bookable_period():
|
|
assert not event.id in [x['id'] for x in data]
|
|
|
|
resp = app.get('/api/agenda/xxx/datetimes/', status=404)
|
|
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
|
|
assert 'data' in resp.json
|
|
assert len(resp.json['data']) == 3
|
|
check_bookability(resp.json['data'])
|
|
assert app.get('/api/agenda/%s/datetimes/' % agenda.id).json == resp.json
|
|
|
|
agenda.minimal_booking_delay = 5
|
|
agenda.save()
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
|
|
assert len(resp.json['data']) == 0
|
|
check_bookability(resp.json['data'])
|
|
|
|
agenda.minimal_booking_delay = 2
|
|
agenda.save()
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
|
|
assert len(resp.json['data']) == 2
|
|
check_bookability(resp.json['data'])
|
|
|
|
agenda.minimal_booking_delay = 0
|
|
agenda.maximal_booking_delay = 3
|
|
agenda.save()
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
|
|
assert len(resp.json['data']) == 2
|
|
check_bookability(resp.json['data'])
|
|
|
|
def test_datetimes_api_wrong_kind(app, some_data):
|
|
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
|
|
agenda.kind = 'meetings'
|
|
agenda.save()
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda.id, status=500)
|
|
|
|
def test_datetime_api_fr(app, some_data):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
with override_settings(LANGUAGE_CODE='fr-fr'):
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
|
# no seconds, hh:mm in 24-hour formats
|
|
assert resp.json['data'][0]['text'].endswith(' 17:00')
|
|
assert resp.json['data'][0]['datetime'].endswith(' 17:00:00')
|
|
assert 'data' in resp.json
|
|
|
|
def test_datetime_api_label(app, some_data):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar2')[0].id
|
|
event = Event.objects.filter(agenda=agenda_id)[0]
|
|
event.label = 'Hello world'
|
|
event.save()
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
|
assert 'Hello world' in [x['text'] for x in resp.json['data']]
|
|
|
|
def test_datetimes_api_meetings_agenda(app, meetings_agenda):
|
|
meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
|
|
api_url = '/api/agenda/%s/meetings/%s/datetimes/' % (
|
|
meeting_type.agenda.slug, meeting_type.slug)
|
|
|
|
resp = app.get('/api/agenda/%s/meetings/xxx/datetimes/' % meeting_type.agenda.slug, status=404)
|
|
|
|
resp = app.get(api_url)
|
|
assert len(resp.json['data']) == 144
|
|
assert resp.json == app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id).json
|
|
|
|
meetings_agenda.minimal_booking_delay = 7
|
|
meetings_agenda.maximal_booking_delay = 28
|
|
meetings_agenda.save()
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
assert len(resp.json['data']) == 54
|
|
|
|
meetings_agenda.minimal_booking_delay = 1
|
|
meetings_agenda.maximal_booking_delay = 56
|
|
meetings_agenda.save()
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
assert len(resp.json['data']) == 144
|
|
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
dt = datetime.datetime.strptime(resp.json['data'][2]['id'].split(':')[1], '%Y-%m-%d-%H%M')
|
|
ev = Event(agenda=meetings_agenda, meeting_type=meeting_type,
|
|
places=1, full=False, start_datetime=make_aware(dt))
|
|
ev.save()
|
|
booking = Booking(event=ev)
|
|
booking.save()
|
|
|
|
resp2 = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
assert len(resp2.json['data']) == 143
|
|
assert resp.json['data'][0] == resp2.json['data'][0]
|
|
assert resp.json['data'][1] == resp2.json['data'][1]
|
|
assert resp.json['data'][3] == resp2.json['data'][2]
|
|
|
|
# test with a timeperiod overlapping current moment, it should get one
|
|
# datetime for the current timeperiod + two from the next week.
|
|
TimePeriod.objects.filter(agenda=meetings_agenda).delete()
|
|
start_time = now() - datetime.timedelta(minutes=10)
|
|
time_period = TimePeriod(agenda=meetings_agenda, weekday=now().weekday(),
|
|
start_time=start_time,
|
|
end_time=start_time + datetime.timedelta(hours=1))
|
|
time_period.save()
|
|
meetings_agenda.minimal_booking_delay = 0
|
|
meetings_agenda.maximal_booking_delay = 10
|
|
meetings_agenda.save()
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
assert len(resp.json['data']) == 3
|
|
|
|
def test_booking_api(app, some_data, user):
|
|
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
|
|
event = Event.objects.filter(agenda=agenda)[0]
|
|
|
|
# unauthenticated
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda.slug, event.id), status=403)
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda.slug, event.id))
|
|
Booking.objects.get(id=resp.json['booking_id'])
|
|
assert Booking.objects.count() == 1
|
|
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda.id, event.id))
|
|
assert Booking.objects.count() == 2
|
|
assert Booking.objects.filter(event__agenda=agenda).count() == 2
|
|
|
|
resp = app.post('/api/agenda/foobar/fillslot/%s/' % event.id, status=404)
|
|
|
|
def test_booking_api_meeting(app, meetings_agenda, user):
|
|
agenda_id = meetings_agenda.id
|
|
meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
event_id = resp.json['data'][2]['id']
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event_id))
|
|
assert Booking.objects.count() == 1
|
|
|
|
resp2 = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
assert len(resp.json['data']) == len(resp2.json['data']) + 1
|
|
|
|
# try booking the same timeslot
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event_id))
|
|
assert resp.json['err'] == 1
|
|
assert resp.json['reason'] == 'sold out'
|
|
|
|
def test_booking_api_meeting_different_durations_book_short(app, meetings_agenda, user):
|
|
agenda_id = meetings_agenda.id
|
|
meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
|
|
|
|
meeting_type_2 = MeetingType(agenda=meetings_agenda, label='Shorter', duration=15)
|
|
meeting_type_2.save()
|
|
|
|
# get long events
|
|
resp_long = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
|
|
# book a short event
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type_2.id)
|
|
event_id = resp.json['data'][0]['id']
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event_id))
|
|
assert Booking.objects.count() == 1
|
|
|
|
# the longer event at the same time shouldn't be available anymore
|
|
resp_long2 = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
assert len(resp_long.json['data']) == len(resp_long2.json['data']) + 1
|
|
assert resp_long.json['data'][1:] == resp_long2.json['data']
|
|
|
|
def test_booking_api_meeting_different_durations_book_long(app, meetings_agenda, user):
|
|
agenda_id = meetings_agenda.id
|
|
meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
|
|
|
|
meeting_type_2 = MeetingType(agenda=meetings_agenda, label='Shorter', duration=15)
|
|
meeting_type_2.save()
|
|
|
|
# get short events
|
|
resp_short = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type_2.id)
|
|
|
|
# book a long event
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
event_id = resp.json['data'][0]['id']
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event_id))
|
|
assert Booking.objects.count() == 1
|
|
|
|
# this should have removed two short events
|
|
resp_short2 = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type_2.id)
|
|
assert len(resp_short.json['data']) == len(resp_short2.json['data']) + 2
|
|
|
|
# book another long event
|
|
event_id = resp.json['data'][10]['id']
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event_id))
|
|
assert Booking.objects.count() == 2
|
|
|
|
resp_short2 = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type_2.id)
|
|
assert len(resp_short.json['data']) == len(resp_short2.json['data']) + 4
|
|
|
|
def test_booking_api_with_data(app, some_data, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
event = Event.objects.filter(agenda_id=agenda_id)[0]
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post_json('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id),
|
|
params={'hello': 'world'})
|
|
assert Booking.objects.count() == 1
|
|
assert Booking.objects.all()[0].extra_data == {'hello': 'world'}
|
|
|
|
def test_booking_cancellation_api(app, some_data, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
event = Event.objects.filter(agenda_id=agenda_id)[0]
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id), status=403)
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id))
|
|
booking_id = resp.json['booking_id']
|
|
assert Booking.objects.count() == 1
|
|
resp = app.delete('/api/booking/%s/' % booking_id)
|
|
assert Booking.objects.filter(cancellation_datetime__isnull=False).count() == 1
|
|
|
|
def test_booking_cancellation_post_api(app, some_data, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
event = Event.objects.filter(agenda_id=agenda_id)[0]
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id), status=403)
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id))
|
|
booking_id = resp.json['booking_id']
|
|
assert Booking.objects.count() == 1
|
|
resp = app.post('/api/booking/%s/cancel/' % booking_id)
|
|
assert Booking.objects.filter(cancellation_datetime__isnull=False).count() == 1
|
|
|
|
# cancel an object that doesn't exist
|
|
resp = app.post('/api/booking/%s/cancel/' % 9999, status=404)
|
|
|
|
# cancel an event that was already cancelled
|
|
resp = app.post('/api/booking/%s/cancel/' % booking_id, status=200)
|
|
assert resp.json['err'] == 1
|
|
|
|
def test_booking_cancellation_post_meeting_api(app, meetings_agenda, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar Meeting')[0].id
|
|
meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
nb_events = len(resp.json['data'])
|
|
event_id = resp.json['data'][2]['id']
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event_id))
|
|
assert Booking.objects.count() == 1
|
|
|
|
booking_id = resp.json['booking_id']
|
|
assert Booking.objects.count() == 1
|
|
resp = app.post('/api/booking/%s/cancel/' % booking_id)
|
|
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
assert len(resp.json['data']) == nb_events
|
|
|
|
# book the same time slot
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event_id))
|
|
assert resp.json['err'] == 0
|
|
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
assert len(resp.json['data']) == nb_events - 1
|
|
|
|
def test_soldout(app, some_data, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
event = Event.objects.filter(agenda_id=agenda_id).exclude(start_datetime__lt=now())[0]
|
|
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
|
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 3
|
|
assert event.id in [x['id'] for x in resp.json['data']]
|
|
|
|
for i in range(event.places):
|
|
Booking(event=event).save()
|
|
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
|
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 2
|
|
assert not event.id in [x['id'] for x in resp.json['data'] if not x.get('disabled')]
|
|
assert event.id in [x['id'] for x in resp.json['data'] if x.get('disabled')]
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id), status=200)
|
|
assert resp.json['err'] == 1
|
|
assert resp.json['reason'] == 'sold out'
|
|
|
|
def test_status(app, some_data, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
event = Event.objects.filter(agenda_id=agenda_id)[0]
|
|
Booking(event=event).save()
|
|
|
|
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, event.id), status=403)
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, 9999), status=404)
|
|
|
|
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, event.id))
|
|
assert resp.json['err'] == 0
|
|
assert resp.json['places']['total'] == 10
|
|
assert resp.json['places']['available'] == 9
|
|
assert resp.json['places']['reserved'] == 1
|
|
assert not 'waiting_list_total' in resp.json['places']
|
|
|
|
Booking(event=event, in_waiting_list=True).save()
|
|
event.waiting_list_places = 5
|
|
event.save()
|
|
resp = app.get('/api/agenda/%s/status/%s/' % (agenda_id, event.id))
|
|
assert resp.json['places']['waiting_list_total'] == 5
|
|
assert resp.json['places']['waiting_list_available'] == 4
|
|
assert resp.json['places']['waiting_list_reserved'] == 1
|
|
|
|
def test_waiting_list_datetimes(app, some_data, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
event = Event.objects.filter(agenda_id=agenda_id).exclude(start_datetime__lt=now())[0]
|
|
event.waiting_list_places = 5
|
|
event.save()
|
|
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
|
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 3
|
|
assert event.id in [x['id'] for x in resp.json['data']]
|
|
|
|
for i in range(event.places):
|
|
Booking(event=event).save()
|
|
|
|
# all places are booked but all the dates are still displayed as there is a
|
|
# waiting list.
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
|
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 3
|
|
|
|
# fill the waiting list
|
|
for i in range(event.waiting_list_places):
|
|
Booking(event=event, in_waiting_list=True).save()
|
|
|
|
# the event datetime should no longer be returned
|
|
resp = app.get('/api/agenda/%s/datetimes/' % agenda_id)
|
|
assert len([x for x in resp.json['data'] if not x.get('disabled')]) == 2
|
|
assert not event.id in [x['id'] for x in resp.json['data'] if not x.get('disabled')]
|
|
assert event.id in [x['id'] for x in resp.json['data'] if x.get('disabled')]
|
|
|
|
def test_waiting_list_booking(app, some_data, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
event = Event.objects.filter(agenda_id=agenda_id).exclude(start_datetime__lt=now())[0]
|
|
event.waiting_list_places = 5
|
|
event.save()
|
|
|
|
for i in range(event.places):
|
|
Booking(event=event).save()
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id), status=200)
|
|
assert resp.json['err'] == 0
|
|
assert resp.json['in_waiting_list'] is True
|
|
|
|
# cancel a booking that was not on the waiting list
|
|
booking = Booking.objects.filter(event=event, in_waiting_list=False)[0]
|
|
booking.cancel()
|
|
|
|
# check new booking is still done on the waiting list
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id), status=200)
|
|
assert resp.json['err'] == 0
|
|
assert resp.json['in_waiting_list'] is True
|
|
|
|
# fill the waiting list
|
|
for i in range(event.waiting_list_places):
|
|
Booking(event=event, in_waiting_list=True).save()
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda_id, event.id), status=200)
|
|
assert resp.json['err'] == 1
|
|
assert resp.json['reason'] == 'sold out'
|
|
|
|
def test_accept_booking(app, some_data, user):
|
|
agenda_id = Agenda.objects.filter(label=u'Foo bar')[0].id
|
|
event = Event.objects.filter(agenda_id=agenda_id).exclude(start_datetime__lt=now())[0]
|
|
event.waiting_list_places = 5
|
|
event.save()
|
|
|
|
# create a booking on the waiting list
|
|
booking = Booking(event=event, in_waiting_list=True)
|
|
booking.save()
|
|
|
|
assert Booking.objects.filter(in_waiting_list=True).count() == 1
|
|
|
|
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
resp = app.post('/api/booking/%s/accept/' % booking.id)
|
|
assert Booking.objects.filter(in_waiting_list=True).count() == 0
|
|
assert Booking.objects.filter(in_waiting_list=False).count() == 1
|
|
|
|
# accept a booking that doesn't exist
|
|
resp = app.post('/api/booking/%s/accept/' % 9999, status=404)
|
|
|
|
# accept a booking that was not in the waiting list
|
|
resp = app.post('/api/booking/%s/accept/' % booking.id, status=200)
|
|
assert resp.json['err'] == 2
|
|
|
|
# accept a booking that was cancelled before
|
|
booking = Booking.objects.get(id=booking.id)
|
|
booking.in_waiting_list = True
|
|
booking.cancel()
|
|
resp = app.post('/api/booking/%s/accept/' % booking.id, status=200)
|
|
assert resp.json['err'] == 1
|
|
assert Booking.objects.filter(in_waiting_list=True).count() == 1
|
|
assert Booking.objects.filter(in_waiting_list=False).count() == 0
|