From ea79320113cdd1f4304bdda178e44538c421c9a6 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Wed, 30 Mar 2022 11:13:04 +0200 Subject: [PATCH] api: allow events without recurrence end date in recurring event list (#63048) --- chrono/agendas/models.py | 2 +- tests/api/test_datetimes.py | 21 ++++++++------------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/chrono/agendas/models.py b/chrono/agendas/models.py index 6c51232d..1fe564d3 100644 --- a/chrono/agendas/models.py +++ b/chrono/agendas/models.py @@ -769,7 +769,7 @@ class Agenda(models.Model): return [ e for e in self.prefetched_recurring_events - if e.recurrence_end_date and e.recurrence_end_date > localtime(now()).date() + if not e.recurrence_end_date or e.recurrence_end_date > localtime(now()).date() ] @transaction.atomic diff --git a/tests/api/test_datetimes.py b/tests/api/test_datetimes.py index 742efb51..6d4489ec 100644 --- a/tests/api/test_datetimes.py +++ b/tests/api/test_datetimes.py @@ -1343,12 +1343,6 @@ def test_recurring_events_api_list(app, freezer): resp = app.get('/api/agendas/recurring-events/', status=400) - # recurring events without recurrence_end_date are not bookable - resp = app.get('/api/agendas/recurring-events/?agendas=%s' % agenda.slug) - assert len(resp.json['data']) == 0 - - event.recurrence_end_date = now() + datetime.timedelta(days=30) - event.save() start_datetime = now() + datetime.timedelta(days=15) Event.objects.create( label='Other', @@ -1393,7 +1387,7 @@ def test_recurring_events_api_list(app, freezer): assert resp.json['err'] == 1 assert resp.json['errors']['sort'][0] == '"invalid" is not a valid choice.' - Event.objects.create( + new_event = Event.objects.create( label='New event one hour before', slug='one-hour-before', start_datetime=now() - datetime.timedelta(hours=1), @@ -1409,7 +1403,6 @@ def test_recurring_events_api_list(app, freezer): recurrence_days=[3], # Thursday places=2, agenda=agenda, - recurrence_end_date=now() + datetime.timedelta(days=30), ) resp = app.get('/api/agendas/recurring-events/?agendas=%s&sort=day' % agenda.slug) assert len(resp.json['data']) == 6 @@ -1420,14 +1413,16 @@ def test_recurring_events_api_list(app, freezer): assert resp.json['data'][4]['id'] == 'foo-bar@example-event:3' assert resp.json['data'][5]['id'] == 'foo-bar@example-event:4' - event.publication_datetime = now() + datetime.timedelta(days=2) - event.save() + freezer.move_to(new_event.recurrence_end_date) resp = app.get('/api/agendas/recurring-events/?agendas=%s' % agenda.slug) - assert len(resp.json['data']) == 3 + assert len(resp.json['data']) == 5 + assert not any('one-hour-before' in x['id'] for x in resp.json['data']) - freezer.move_to(event.recurrence_end_date) + event.publication_datetime = now() + datetime.timedelta(days=2) + event.save() resp = app.get('/api/agendas/recurring-events/?agendas=%s' % agenda.slug) - assert len(resp.json['data']) == 1 + assert len(resp.json['data']) == 2 + assert not any('example_event' in x['id'] for x in resp.json['data']) @pytest.mark.freeze_time('2021-09-06 12:00') -- 2.30.2