326 |
326 |
'2021-11-20',
|
327 |
327 |
'2021-11-29',
|
328 |
328 |
'2021-12-02',
|
329 |
329 |
'2021-12-04',
|
330 |
330 |
'2021-12-13',
|
331 |
331 |
'2021-12-16',
|
332 |
332 |
'2021-12-18',
|
333 |
333 |
]
|
|
334 |
|
|
335 |
|
|
336 |
def test_update_event(app, user):
|
|
337 |
api_url = '/api/agenda/%s/event/%s/' % ('nop', 'nop')
|
|
338 |
|
|
339 |
# no authentication
|
|
340 |
resp = app.patch(api_url, status=401)
|
|
341 |
assert resp.json['detail'] == 'Authentication credentials were not provided.'
|
|
342 |
|
|
343 |
# wrong password
|
|
344 |
app.authorization = ('Basic', ('john.doe', 'wrong'))
|
|
345 |
resp = app.patch(api_url, status=401)
|
|
346 |
assert resp.json['detail'] == 'Invalid username/password.'
|
|
347 |
|
|
348 |
app.authorization = ('Basic', ('john.doe', 'password'))
|
|
349 |
|
|
350 |
# missing agenda
|
|
351 |
resp = app.patch(api_url, status=404)
|
|
352 |
assert resp.json['detail'] == 'Not found.'
|
|
353 |
|
|
354 |
meeting_agenda = Agenda.objects.create(label='Foo bar Meeting', kind='meetings')
|
|
355 |
|
|
356 |
# using meeting agenda
|
|
357 |
api_url = '/api/agenda/%s/event/%s/' % (meeting_agenda.slug, 'nop')
|
|
358 |
resp = app.patch(api_url, status=404)
|
|
359 |
assert resp.json['detail'] == 'Not found.'
|
|
360 |
|
|
361 |
agenda = Agenda.objects.create(label='Foo bar')
|
|
362 |
|
|
363 |
# missing event
|
|
364 |
api_url = '/api/agenda/%s/event/%s/' % (agenda.slug, 'nop')
|
|
365 |
resp = app.patch(api_url, status=404)
|
|
366 |
assert resp.json['detail'] == 'Not found.'
|
|
367 |
|
|
368 |
# missing recurring event
|
|
369 |
api_url = '/api/agenda/%s/event/%s/' % (agenda.slug, 'nop:2021-11-15-1538')
|
|
370 |
resp = app.patch(api_url, status=400)
|
|
371 |
assert resp.json['err']
|
|
372 |
assert resp.json['err_desc'] == 'unknown recurring event slug: nop'
|
|
373 |
|
|
374 |
event = Event.objects.create(agenda=agenda, start_datetime=now(), places=10, waiting_list_places=5)
|
|
375 |
api_url = '/api/agenda/%s/event/%s/' % (agenda.slug, event.slug)
|
|
376 |
|
|
377 |
# update with errors in datetime parts
|
|
378 |
params = {
|
|
379 |
'start_datetime': '2021-11-15 minuit',
|
|
380 |
'recurrence_days': '7, 8',
|
|
381 |
}
|
|
382 |
resp = app.patch(api_url, params=params, status=400)
|
|
383 |
assert resp.json['err']
|
|
384 |
assert resp.json['err_desc'] == 'invalid payload'
|
|
385 |
assert 'Datetime has wrong format' in resp.json['errors']['start_datetime'][0]
|
|
386 |
assert resp.json['errors']['recurrence_days']['0'][0] == 'Ensure this value is less than or equal to 6.'
|
|
387 |
|
|
388 |
# update with almost all optional managed fields
|
|
389 |
params = {
|
|
390 |
'start_datetime': '2021-11-15 15:38',
|
|
391 |
'duration': 42,
|
|
392 |
'publication_date': '2021-09-20',
|
|
393 |
'places': 8,
|
|
394 |
'waiting_list_places': 3,
|
|
395 |
'label': 'FOO camp',
|
|
396 |
'description': 'An event',
|
|
397 |
'pricing': 'free',
|
|
398 |
'url': 'http://example.org/foo/bar/?',
|
|
399 |
}
|
|
400 |
resp = app.patch(api_url, params=params)
|
|
401 |
assert not resp.json['err']
|
|
402 |
event = Event.objects.filter(agenda=agenda).get(slug=event.slug)
|
|
403 |
assert event.duration == 42
|
|
404 |
assert event.places == 8
|
|
405 |
assert event.waiting_list_places == 3
|
|
406 |
assert event.label == 'FOO camp'
|
|
407 |
assert event.description == 'An event'
|
|
408 |
assert event.pricing == 'free'
|
|
409 |
assert event.url == 'http://example.org/foo/bar/?'
|
|
410 |
|
|
411 |
# update event as a recurring event
|
|
412 |
params = {
|
|
413 |
'recurrence_days': '0,3,5',
|
|
414 |
'recurrence_week_interval': 2,
|
|
415 |
'recurrence_end_date': '2021-12-27',
|
|
416 |
}
|
|
417 |
resp = app.patch(api_url, params=params)
|
|
418 |
assert not resp.json['err']
|
|
419 |
event = Event.objects.filter(agenda=agenda).get(slug=event.slug)
|
|
420 |
assert event.recurrences.count() == 9
|
|
421 |
assert [x.places for x in event.recurrences.all()] == [8] * 9
|
|
422 |
|
|
423 |
recurrence_slug = event.recurrences.first().slug
|
|
424 |
assert recurrence_slug == 'foo-bar-event--2021-11-15-1538'
|
|
425 |
recurrence_url = '/api/agenda/%s/event/%s/' % (agenda.slug, 'foo-bar-event:2021-11-15-1538')
|
|
426 |
|
|
427 |
# update unprotected fields of one of the event recurrencies
|
|
428 |
params = {
|
|
429 |
'start_datetime': '2021-11-14 14:00',
|
|
430 |
'duration': 43,
|
|
431 |
'places': 9,
|
|
432 |
'waiting_list_places': 4,
|
|
433 |
'label': 'BAR camp',
|
|
434 |
'description': 'An occurence of an event recurrence',
|
|
435 |
'pricing': '5€',
|
|
436 |
'url': 'http://example.org/bar/bar/',
|
|
437 |
}
|
|
438 |
resp = app.patch(recurrence_url, params=params)
|
|
439 |
assert not resp.json['err']
|
|
440 |
recurrence = Event.objects.filter(agenda=agenda).get(slug=recurrence_slug)
|
|
441 |
assert recurrence.duration == 43
|
|
442 |
assert recurrence.places == 9
|
|
443 |
assert recurrence.waiting_list_places == 4
|
|
444 |
assert recurrence.label == 'BAR camp'
|
|
445 |
assert recurrence.description == 'An occurence of an event recurrence'
|
|
446 |
assert recurrence.pricing == '5€'
|
|
447 |
assert recurrence.url == 'http://example.org/bar/bar/'
|
|
448 |
|
|
449 |
# try to update protected fields of one of the event recurrencies
|
|
450 |
params = {
|
|
451 |
'publication_date': '2021-11-15',
|
|
452 |
}
|
|
453 |
resp = app.patch(recurrence_url, params=params, status=400)
|
|
454 |
assert resp.json['err']
|
|
455 |
assert 'cannot be modified' in resp.json['err_desc']
|
|
456 |
|
|
457 |
# update protected fields of one of the event recurrencies providing same value
|
|
458 |
assert 'cannot be modified' in resp.json['err_desc']
|
|
459 |
params = {
|
|
460 |
'recurrence_week_interval': 1,
|
|
461 |
}
|
|
462 |
resp = app.patch(recurrence_url, params=params)
|
|
463 |
assert not resp.json['err']
|
|
464 |
|
|
465 |
booking = Booking.objects.create(event=event.recurrences.all()[2])
|
|
466 |
|
|
467 |
# update unprotected fields
|
|
468 |
params = {
|
|
469 |
'places': 7,
|
|
470 |
}
|
|
471 |
resp = app.patch(api_url, params=params)
|
|
472 |
assert not resp.json['err']
|
|
473 |
event = Event.objects.filter(agenda=agenda).get(slug=event.slug)
|
|
474 |
assert [x.places for x in event.recurrences.all()] == [7] * 9
|
|
475 |
|
|
476 |
# try to update recurring event protected fields
|
|
477 |
params = {
|
|
478 |
'recurrence_days': '1,2',
|
|
479 |
}
|
|
480 |
resp = app.patch(api_url, params=params, status=400)
|
|
481 |
assert resp.json['err']
|
|
482 |
assert 'cannot be modified' in resp.json['err_desc']
|
|
483 |
|
|
484 |
assert booking.event.start_datetime.date() == datetime.date(2021, 11, 20)
|
|
485 |
|
|
486 |
# try to reduce recurrence end date before booked event
|
|
487 |
params = {
|
|
488 |
'recurrence_end_date': '2021-11-20',
|
|
489 |
}
|
|
490 |
resp = app.patch(api_url, params=params, status=400)
|
|
491 |
assert resp.json['err']
|
|
492 |
assert 'bookings exist after this date.' in resp.json['err_desc']
|
|
493 |
|
|
494 |
# reduce recurrence end date after booked event
|
|
495 |
params = {
|
|
496 |
'recurrence_end_date': '2021-11-21',
|
|
497 |
}
|
|
498 |
resp = app.patch(api_url, params=params)
|
|
499 |
assert not resp.json['err']
|
|
500 |
event = Event.objects.filter(agenda=agenda).get(slug=event.slug)
|
|
501 |
assert event.recurrences.count() == 3
|
|
502 |
|
|
503 |
booking.cancel()
|
|
504 |
|
|
505 |
# update no more protected fields
|
|
506 |
params = {
|
|
507 |
'recurrence_days': '1,2,3,4,5',
|
|
508 |
'recurrence_week_interval': 1,
|
|
509 |
}
|
|
510 |
resp = app.patch(api_url, params=params)
|
|
511 |
assert not resp.json['err']
|
|
512 |
event = Event.objects.filter(agenda=agenda).get(slug=event.slug)
|
|
513 |
assert event.recurrences.count() == 5
|
334 |
|
-
|