329 |
329 |
assert resp.json['datetime'] == localtime(event.start_datetime).isoformat()
|
330 |
330 |
assert 'accept_url' not in resp.json['api']
|
331 |
331 |
assert 'cancel_url' in resp.json['api']
|
|
332 |
assert 'ics_url' in resp.json['api']
|
332 |
333 |
assert urlparse.urlparse(resp.json['api']['cancel_url']).netloc
|
|
334 |
assert urlparse.urlparse(resp.json['api']['ics_url']).netloc
|
333 |
335 |
assert Booking.objects.count() == 1
|
334 |
336 |
|
335 |
337 |
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda.id, event.id))
|
... | ... | |
370 |
372 |
|
371 |
373 |
resp = app.post('/api/agenda/233/fillslot/%s/' % event.id, status=404)
|
372 |
374 |
|
|
375 |
def test_booking_ics(app, some_data, meetings_agenda, user):
|
|
376 |
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
|
|
377 |
event = [x for x in Event.objects.filter(agenda=agenda) if x.in_bookable_period()][0]
|
|
378 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
379 |
resp = app.post('/api/agenda/%s/fillslot/%s/' % (agenda.slug, event.id))
|
|
380 |
|
|
381 |
assert Booking.objects.count() == 1
|
|
382 |
assert 'ics_url' in resp.json['api']
|
|
383 |
assert urlparse.urlparse(resp.json['api']['cancel_url']).netloc
|
|
384 |
assert urlparse.urlparse(resp.json['api']['ics_url']).netloc
|
|
385 |
|
|
386 |
formatted_start_date = event.start_datetime.strftime('%Y%m%dT%H%M%S')
|
|
387 |
booking_ics = Booking.objects.get(id=resp.json['booking_id']).get_ics()
|
|
388 |
assert 'UID:%s-%s-%s\r\n' % (event.start_datetime.isoformat(), agenda.pk, resp.json['booking_id']) in booking_ics
|
|
389 |
assert 'SUMMARY:\r\n' in booking_ics
|
|
390 |
assert 'DTSTART:%sZ\r\n' % formatted_start_date in booking_ics
|
|
391 |
assert 'DTEDND:' not in booking_ics
|
|
392 |
|
|
393 |
# test with additional data
|
|
394 |
resp = app.post_json('/api/agenda/%s/fillslot/%s/' % (agenda.id, event.id),
|
|
395 |
params={'label': 'foo', 'user_name': 'bar', 'backoffice_url': 'http://example.net/',
|
|
396 |
'url': 'http://example.com/booking'})
|
|
397 |
assert Booking.objects.count() == 2
|
|
398 |
booking_ics = Booking.objects.get(id=resp.json['booking_id']).get_ics()
|
|
399 |
assert 'SUMMARY:foo\r\n' in booking_ics
|
|
400 |
assert 'ATTENDEE:bar\r\n' in booking_ics
|
|
401 |
assert 'URL:http://example.com/booking\r\n' in booking_ics
|
|
402 |
|
|
403 |
# extra data stored in extra_data field
|
|
404 |
resp = app.post_json('/api/agenda/%s/fillslot/%s/' % (agenda.id, event.id),
|
|
405 |
params={'label': 'l', 'user_name': 'u', 'backoffice_url': '', 'location': 'bar',
|
|
406 |
'comment': 'booking comment', 'description': 'booking description'})
|
|
407 |
assert Booking.objects.count() == 3
|
|
408 |
booking_id = resp.json['booking_id']
|
|
409 |
booking = Booking.objects.get(id=booking_id)
|
|
410 |
booking_ics = booking.get_ics()
|
|
411 |
assert 'COMMENT:booking comment\r\n' in booking_ics
|
|
412 |
assert 'LOCATION:bar\r\n' in booking_ics
|
|
413 |
assert 'DESCRIPTION:booking description\r\n' in booking_ics
|
|
414 |
|
|
415 |
# unauthenticated
|
|
416 |
app.authorization = None
|
|
417 |
app.get('/api/booking/%s/ics/' % resp.json['booking_id'], status=403)
|
|
418 |
|
|
419 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
420 |
resp = app.get('/api/booking/%s/ics/' % resp.json['booking_id'])
|
|
421 |
assert resp.headers['Content-Type'] == 'text/calendar'
|
|
422 |
assert resp.headers['Content-Disposition'] == 'inline; filename=%s.ics;' % booking_id
|
|
423 |
|
|
424 |
params = {'description': 'custom booking description', 'location': 'custom booking location',
|
|
425 |
'comment': 'custom comment', 'url': 'http://example.com/custom'}
|
|
426 |
resp = app.get('/api/booking/%s/ics/' % booking_id, params=params)
|
|
427 |
assert 'DESCRIPTION:custom booking description\r\n' in resp.text
|
|
428 |
assert 'LOCATION:custom booking location\r\n' in resp.text
|
|
429 |
assert 'COMMENT:custom comment\r\n' in resp.text
|
|
430 |
assert 'URL:http://example.com/custom\r\n' in resp.text
|
|
431 |
|
|
432 |
meetings_agenda_id = Agenda.objects.filter(label=u'Foo bar Meeting')[0].id
|
|
433 |
meeting_type = MeetingType.objects.get(agenda=meetings_agenda)
|
|
434 |
resp = app.get('/api/agenda/meetings/%s/datetimes/' % meeting_type.id)
|
|
435 |
event = resp.json['data'][2]
|
|
436 |
resp = app.post('/api/agenda/%s/fillslot/%s/' % (meetings_agenda_id, event['id']))
|
|
437 |
assert Booking.objects.count() == 4
|
|
438 |
assert 'ics_url' in resp.json['api']
|
|
439 |
booking = Booking.objects.get(id=resp.json['booking_id'])
|
|
440 |
booking_ics = booking.get_ics()
|
|
441 |
start = booking.event.start_datetime.strftime('%Y%m%dT%H%M%S')
|
|
442 |
end = (booking.event.start_datetime + datetime.timedelta(minutes=booking.event.meeting_type.duration)).strftime('%Y%m%dT%H%M%S')
|
|
443 |
assert "DTSTART:%sZ\r\n" % start in booking_ics
|
|
444 |
assert "DTEND:%sZ\r\n" % end in booking_ics
|
|
445 |
|
373 |
446 |
def test_booking_api_fillslots(app, some_data, user):
|
374 |
447 |
agenda = Agenda.objects.filter(label=u'Foo bar')[0]
|
375 |
448 |
events_ids = [x.id for x in Event.objects.filter(agenda=agenda) if x.in_bookable_period()]
|
... | ... | |
779 |
852 |
assert resp.json['in_waiting_list'] is True
|
780 |
853 |
assert 'accept_url' in resp.json['api']
|
781 |
854 |
assert 'cancel_url' in resp.json['api']
|
|
855 |
assert 'ics_url' in resp.json['api']
|
782 |
856 |
assert urlparse.urlparse(resp.json['api']['accept_url']).netloc
|
783 |
857 |
assert urlparse.urlparse(resp.json['api']['cancel_url']).netloc
|
|
858 |
assert urlparse.urlparse(resp.json['api']['ics_url']).netloc
|
784 |
859 |
|
785 |
860 |
# cancel a booking that was not on the waiting list
|
786 |
861 |
booking = Booking.objects.filter(event=event, in_waiting_list=False)[0]
|
... | ... | |
933 |
1008 |
assert resp.json['datetime'] == localtime(events[0].start_datetime).isoformat()
|
934 |
1009 |
assert 'accept_url' not in resp.json['api']
|
935 |
1010 |
assert 'cancel_url' in resp.json['api']
|
|
1011 |
assert 'ics_url' in resp.json['api']
|
936 |
1012 |
for event in events:
|
937 |
1013 |
assert Event.objects.get(id=event.id).booked_places == 3
|
938 |
1014 |
|
939 |
|
-
|