0001-api-support-overlapping-events-44644.patch
chrono/api/views.py | ||
---|---|---|
177 | 177 |
bookings.update( |
178 | 178 |
( |
179 | 179 |
desk_id, |
180 |
IntervalSet.from_ordered(
|
|
180 |
IntervalSet( |
|
181 | 181 |
(event_start_datetime, event_start_datetime + datetime.timedelta(minutes=event_duration)) |
182 | 182 |
for desk_id, event_start_datetime, event_duration in values |
183 | 183 |
), |
tests/test_api.py | ||
---|---|---|
3074 | 3074 |
assert len([x for x in resp.json['data'] if x['disabled']]) == 2 |
3075 | 3075 | |
3076 | 3076 | |
3077 |
def test_datetimes_api_concurrent_bookings(app, user, meetings_agenda): |
|
3078 |
meeting_type = MeetingType.objects.get(agenda=meetings_agenda) |
|
3079 |
api_url = '/api/agenda/%s/meetings/%s/datetimes/' % (meeting_type.agenda.slug, meeting_type.slug) |
|
3080 |
assert Booking.objects.count() == 0 |
|
3081 |
resp = app.get(api_url) |
|
3082 |
assert resp.json['data'][0]['datetime'] == '2017-05-22 10:00:00' |
|
3083 | ||
3084 |
# make a booking |
|
3085 |
fillslot_url = resp.json['data'][0]['api']['fillslot_url'] |
|
3086 |
app.authorization = ('Basic', ('john.doe', 'password')) |
|
3087 |
resp = app.post(fillslot_url) |
|
3088 |
assert Booking.objects.count() == 1 |
|
3089 | ||
3090 |
# make a second one artificially on an overlapping slot |
|
3091 |
meeting_type = MeetingType.objects.create(agenda=meetings_agenda, label='Boo', duration=8) |
|
3092 |
booking = Booking.objects.first() |
|
3093 |
event = booking.event |
|
3094 |
new_event = Event.objects.create( |
|
3095 |
meeting_type=meeting_type, |
|
3096 |
start_datetime=event.start_datetime, |
|
3097 |
desk=event.desk, |
|
3098 |
places=event.places, |
|
3099 |
agenda=meetings_agenda, |
|
3100 |
) |
|
3101 |
Booking.objects.create(event=new_event) |
|
3102 | ||
3103 |
# should not crash and slot not showing up |
|
3104 |
resp = app.get(api_url) |
|
3105 |
assert resp.json['data'][0]['datetime'] == '2017-05-22 10:00:00' |
|
3106 |
assert resp.json['data'][0]['disabled'] is True |
|
3107 | ||
3108 | ||
3077 | 3109 |
def test_agenda_detail_routing(app, meetings_agenda): |
3078 | 3110 |
api_url = '/api/agenda/%s/' % meetings_agenda.slug |
3079 | 3111 |
resp = app.get(api_url) |
3080 |
- |