agendas: use iso week days in events and shared custody (#79168)

This commit is contained in:
Valentin Deniaud 2023-06-28 12:46:16 +02:00
parent 747928c680
commit 900300dd05
22 changed files with 405 additions and 367 deletions

View File

@ -3,6 +3,8 @@
import django.contrib.postgres.fields
from django.db import migrations, models
from chrono.agendas.models import WEEKDAY_CHOICES
class Migration(migrations.Migration):
dependencies = [
@ -14,9 +16,7 @@ class Migration(migrations.Migration):
model_name='event',
name='recurrence_days',
field=django.contrib.postgres.fields.ArrayField(
base_field=models.IntegerField(
choices=[(0, 'Mo'), (1, 'Tu'), (2, 'We'), (3, 'Th'), (4, 'Fr'), (5, 'Sa'), (6, 'Su')]
),
base_field=models.IntegerField(choices=WEEKDAY_CHOICES),
blank=True,
null=True,
size=None,

View File

@ -4,6 +4,8 @@ import django.contrib.postgres.fields
import django.db.models.deletion
from django.db import migrations, models
from chrono.agendas.models import WEEKDAY_CHOICES
class Migration(migrations.Migration):
dependencies = [
@ -60,17 +62,7 @@ class Migration(migrations.Migration):
(
'days',
django.contrib.postgres.fields.ArrayField(
base_field=models.IntegerField(
choices=[
(0, 'Mo'),
(1, 'Tu'),
(2, 'We'),
(3, 'Th'),
(4, 'Fr'),
(5, 'Sa'),
(6, 'Su'),
]
),
base_field=models.IntegerField(choices=WEEKDAY_CHOICES),
size=None,
verbose_name='Days',
),

View File

@ -0,0 +1,27 @@
# Generated by Django 3.2.18 on 2023-06-28 10:46
import django.db.models.expressions
import django.db.models.functions.datetime
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agendas', '0155_event_triggers'),
]
operations = [
migrations.RemoveIndex(
model_name='event',
name='start_datetime_dow_index',
),
migrations.AddIndex(
model_name='event',
index=models.Index(
django.db.models.functions.datetime.ExtractIsoWeekDay('start_datetime'),
django.db.models.expressions.F('start_datetime'),
condition=models.Q(('cancelled', False)),
name='start_datetime_dow_index',
),
),
]

View File

@ -51,7 +51,7 @@ from django.db.models import (
Subquery,
Value,
)
from django.db.models.functions import Cast, Coalesce, Concat, ExtractWeek, ExtractWeekDay, JSONObject
from django.db.models.functions import Cast, Coalesce, Concat, ExtractIsoWeekDay, ExtractWeek, JSONObject
from django.template import (
Context,
RequestContext,
@ -95,24 +95,25 @@ AGENDA_VIEWS = (
('open_events', _('Open events')),
)
WEEKDAYS_PLURAL = {
0: _('Mondays'),
1: _('Tuesdays'),
2: _('Wednesdays'),
3: _('Thursdays'),
4: _('Fridays'),
5: _('Saturdays'),
6: _('Sundays'),
ISO_WEEKDAYS = {index + 1: day for index, day in WEEKDAYS.items()}
ISO_WEEKDAYS_PLURAL = {
1: _('Mondays'),
2: _('Tuesdays'),
3: _('Wednesdays'),
4: _('Thursdays'),
5: _('Fridays'),
6: _('Saturdays'),
7: _('Sundays'),
}
WEEKDAY_CHOICES = [
(0, _('Mo')),
(1, _('Tu')),
(2, _('We')),
(3, _('Th')),
(4, _('Fr')),
(5, _('Sa')),
(6, _('Su')),
(1, _('Mo')),
(2, _('Tu')),
(3, _('We')),
(4, _('Th')),
(5, _('Fr')),
(6, _('Sa')),
(7, _('Su')),
]
@ -934,15 +935,14 @@ class Agenda(models.Model):
guardian__user_external_id=guardian_external_id,
agenda=agenda,
)
.annotate(day=Func(F('days'), function='unnest', output_field=models.IntegerField()))
.annotate(week_day=(F('day') + 1) % 7 + 1) # convert ISO day number to db lookup day number
.annotate(week_day=Func(F('days'), function='unnest', output_field=models.IntegerField()))
.values('week_day')
)
rules_lookup = (
Q(start_datetime__week_day__in=rules.filter(weeks=''))
| Q(start_datetime__week_day__in=rules.filter(weeks='even'), odd_week=False)
| Q(start_datetime__week_day__in=rules.filter(weeks='odd'), odd_week=True)
Q(start_datetime__iso_week_day__in=rules.filter(weeks=''))
| Q(start_datetime__iso_week_day__in=rules.filter(weeks='even'), odd_week=False)
| Q(start_datetime__iso_week_day__in=rules.filter(weeks='odd'), odd_week=True)
)
all_periods = SharedCustodyPeriod.objects.filter(
@ -1990,7 +1990,7 @@ class Event(models.Model):
unique_together = ('agenda', 'slug')
indexes = [
models.Index(
ExtractWeekDay('start_datetime'),
ExtractIsoWeekDay('start_datetime'),
'start_datetime',
name='start_datetime_dow_index',
condition=models.Q(cancelled=False),
@ -2228,11 +2228,7 @@ class Event(models.Model):
qs, agenda_slugs, user_external_id, start_datetime, end_datetime
):
recurrences = Event.objects.filter(primary_event=OuterRef('pk'))
recurrences = recurrences.annotate(
dj_weekday=ExtractWeekDay('start_datetime'),
dj_weekday_int=Cast('dj_weekday', models.IntegerField()),
weekday=(F('dj_weekday_int') - 2) % 7,
)
recurrences = recurrences.annotate(weekday=ExtractIsoWeekDay('start_datetime'))
recurrences_with_overlaps = Event.annotate_queryset_with_booked_event_overlaps(
recurrences, agenda_slugs, user_external_id, start_datetime, end_datetime
).filter(has_overlap=True)
@ -2330,6 +2326,11 @@ class Event(models.Model):
)
except ValueError:
raise AgendaImportError(_('Bad datetime format "%s"') % data['start_datetime'])
if data.get('recurrence_days'):
# keep stable weekday numbering after switch to ISO in db
data['recurrence_days'] = [i + 1 for i in data['recurrence_days']]
data = clean_import_data(cls, data)
if data.get('slug'):
event, dummy = cls.objects.update_or_create(
@ -2367,7 +2368,13 @@ class Event(models.Model):
'publication_datetime': make_naive(self.publication_datetime).strftime('%Y-%m-%d %H:%M:%S')
if self.publication_datetime
else None,
'recurrence_days': self.recurrence_days,
'recurrence_days': [
# keep stable weekday numbering after switch to ISO in db
i - 1
for i in self.recurrence_days
]
if self.recurrence_days
else None,
'recurrence_week_interval': self.recurrence_week_interval,
'recurrence_end_date': recurrence_end_date,
'places': self.places,
@ -2475,12 +2482,12 @@ class Event(models.Model):
elif days_count > 1 and (self.recurrence_days[-1] - self.recurrence_days[0]) == days_count - 1:
# days are contiguous
repeat = _('From %(weekday)s to %(last_weekday)s') % {
'weekday': str(WEEKDAYS[self.recurrence_days[0]]),
'last_weekday': str(WEEKDAYS[self.recurrence_days[-1]]),
'weekday': str(ISO_WEEKDAYS[self.recurrence_days[0]]),
'last_weekday': str(ISO_WEEKDAYS[self.recurrence_days[-1]]),
}
else:
repeat = _('On %(weekdays)s') % {
'weekdays': ', '.join([str(WEEKDAYS_PLURAL[i]) for i in self.recurrence_days])
'weekdays': ', '.join([str(ISO_WEEKDAYS_PLURAL[i]) for i in self.recurrence_days])
}
recurrence_display = _('%(On_day_x)s at %(time)s') % {'On_day_x': repeat, 'time': time}
@ -2514,7 +2521,7 @@ class Event(models.Model):
def recurrence_rule(self):
recurrence_rule = {
'freq': WEEKLY,
'byweekday': self.recurrence_days,
'byweekday': [i - 1 for i in self.recurrence_days or []],
'interval': self.recurrence_week_interval,
}
if self.recurrence_end_date:
@ -4005,7 +4012,7 @@ class SharedCustodyRule(models.Model):
def get_slots(self, min_date, max_date):
recurrence_rule = {
'freq': WEEKLY,
'byweekday': self.days,
'byweekday': [i - 1 for i in self.days],
}
if self.weeks == 'odd':
recurrence_rule['byweekno'] = list(range(1, 55, 2))
@ -4025,12 +4032,12 @@ class SharedCustodyRule(models.Model):
elif days_count > 1 and (self.days[-1] - self.days[0]) == days_count - 1:
# days are contiguous
repeat = _('from %(weekday)s to %(last_weekday)s') % {
'weekday': str(WEEKDAYS[self.days[0]]),
'last_weekday': str(WEEKDAYS[self.days[-1]]),
'weekday': str(ISO_WEEKDAYS[self.days[0]]),
'last_weekday': str(ISO_WEEKDAYS[self.days[-1]]),
}
else:
repeat = _('on %(weekdays)s') % {
'weekdays': ', '.join([str(WEEKDAYS_PLURAL[i]) for i in self.days])
'weekdays': ', '.join([str(ISO_WEEKDAYS_PLURAL[i]) for i in self.days])
}
if self.weeks == 'odd':

View File

@ -224,8 +224,6 @@ class RecurringFillslotsSerializer(MultipleAgendasEventsFillSlotsSerializer):
% {'event_slug': event_slug, 'agenda_slug': agenda_slug}
)
# convert ISO day number to db lookup day number
day = (day + 1) % 7 + 1
slots[agenda_slug][event_slug].append(day)
return slots
@ -512,6 +510,10 @@ class EventSerializer(serializers.ModelSerializer):
**(field_options.get(custom_field['field_type']) or {}),
)
def validate_recurrence_days(self, value):
# keep stable weekday numbering after switch to ISO in db
return [i + 1 for i in value]
def validate(self, attrs):
if not self.instance.agenda.events_type:
return attrs
@ -537,6 +539,9 @@ class EventSerializer(serializers.ModelSerializer):
def to_representation(self, instance):
ret = super().to_representation(instance)
if ret.get('recurrence_days'):
# keep stable weekday numbering after switch to ISO in db
ret['recurrence_days'] = [i - 1 for i in ret['recurrence_days']]
if not self.instance.agenda.events_type:
return ret
defaults = {

View File

@ -29,7 +29,6 @@ from django.http import Http404, HttpResponse
from django.shortcuts import get_object_or_404
from django.template import Context, Template, TemplateSyntaxError, VariableDoesNotExist
from django.urls import reverse
from django.utils.dates import WEEKDAYS
from django.utils.encoding import force_str
from django.utils.formats import date_format
from django.utils.translation import gettext
@ -43,6 +42,7 @@ from rest_framework.generics import ListAPIView
from rest_framework.views import APIView
from chrono.agendas.models import (
ISO_WEEKDAYS,
Agenda,
Booking,
BookingColor,
@ -190,7 +190,7 @@ def get_event_text(event, agenda, day=None):
)
elif day is not None:
event_text = _('%(weekday)s: %(event)s') % {
'weekday': WEEKDAYS[day].capitalize(),
'weekday': ISO_WEEKDAYS[day].capitalize(),
'event': event_text,
}
return event_text
@ -239,7 +239,11 @@ def get_event_detail(
if event.recurrence_days:
details.update(
{
'recurrence_days': event.recurrence_days,
'recurrence_days': [
# keep stable weekday numbering after switch to ISO in db
i - 1
for i in event.recurrence_days
],
'recurrence_week_interval': event.recurrence_week_interval,
'recurrence_end_date': event.recurrence_end_date,
}
@ -971,7 +975,7 @@ class RecurringEventsList(APIView):
for agenda in agendas:
for event in agenda.prefetched_events:
if event.primary_event_id:
days_by_event[event.primary_event_id].add(event.start_datetime.weekday())
days_by_event[event.primary_event_id].add(event.start_datetime.isoweekday())
recurring_events = Event.objects.filter(pk__in=days_by_event).select_related(
'agenda', 'agenda__category'
)
@ -1041,7 +1045,7 @@ class RecurringEventsList(APIView):
'text': get_event_text(event, event.agenda, event.day),
'slug': event.slug,
'label': event.label or '',
'day': WEEKDAYS[event.day].capitalize(),
'day': ISO_WEEKDAYS[event.day].capitalize(),
'date': format_response_date(event.start_datetime),
'datetime': format_response_datetime(event.start_datetime),
'description': event.description,
@ -1825,7 +1829,7 @@ class RecurringFillslots(APIView):
lookups = {
'agenda__slug': agenda_slug,
'primary_event__slug': event_slug,
'start_datetime__week_day__in': days,
'start_datetime__iso_week_day__in': days,
}
if agenda.minimal_booking_delay:
lookups.update({'start_datetime__gte': agenda.min_booking_datetime})

View File

@ -281,7 +281,7 @@ def test_datetimes_api_exclude_slots(app):
event = Event.objects.create(
slug='recurrent',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=15),
places=2,
agenda=agenda,
@ -365,7 +365,7 @@ def test_datetimes_api_user_external_id(app):
event = Event.objects.create(
slug='recurrent',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=15),
places=2,
agenda=agenda,
@ -660,7 +660,7 @@ def test_datetimes_api_meta(app, freezer):
slug='abc',
label='Test',
start_datetime=localtime(),
recurrence_days=[localtime().weekday()],
recurrence_days=[localtime().isoweekday()],
recurrence_end_date=localtime() + datetime.timedelta(days=15),
places=5,
agenda=agenda,
@ -679,7 +679,7 @@ def test_recurring_events_api(app, user, freezer):
slug='abc',
label="Rock'n roll",
start_datetime=localtime(),
recurrence_days=[localtime().weekday()],
recurrence_days=[localtime().isoweekday()],
recurrence_end_date=localtime() + datetime.timedelta(days=30),
places=5,
agenda=agenda,
@ -749,7 +749,7 @@ def test_recurring_events_api_various_times(app, user, mock_now):
event = Event.objects.create(
slug='abc',
start_datetime=localtime(),
recurrence_days=[localtime().weekday()],
recurrence_days=[localtime().isoweekday()],
recurrence_end_date=localtime() + datetime.timedelta(days=30),
places=5,
agenda=agenda,
@ -797,7 +797,7 @@ def test_recurring_events_api_exceptions(app, user, freezer):
event = Event.objects.create(
slug='abc',
start_datetime=localtime(),
recurrence_days=[localtime().weekday()],
recurrence_days=[localtime().isoweekday()],
recurrence_end_date=localtime() + datetime.timedelta(days=30),
places=5,
agenda=agenda,
@ -1253,7 +1253,7 @@ def test_past_datetimes_recurring_event(app, user):
event = Event.objects.create(
label='Recurring',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=60),
places=5,
agenda=agenda,

View File

@ -41,7 +41,7 @@ def test_datetimes_multiple_agendas(app):
event = Event.objects.create( # base recurring event not visible in datetimes api
slug='recurring',
start_datetime=now() + datetime.timedelta(hours=1),
recurrence_days=[localtime().weekday()],
recurrence_days=[localtime().isoweekday()],
recurrence_end_date=now() + datetime.timedelta(days=15),
places=5,
agenda=first_agenda,
@ -189,7 +189,7 @@ def test_datetimes_multiple_agendas(app):
event = Event.objects.create( # base recurrring event not visible in datetimes api
slug='recurring-in-past',
start_datetime=now() - datetime.timedelta(days=15, hours=1),
recurrence_days=[localtime().weekday()],
recurrence_days=[localtime().isoweekday()],
recurrence_end_date=now(),
places=5,
agenda=first_agenda,
@ -427,8 +427,8 @@ def test_datetimes_multiple_agendas_queries(app):
date_end=now() - datetime.timedelta(days=5 + 2 * i + 1),
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='odd')
with CaptureQueriesContext(connection) as ctx:
resp = app.get(
@ -600,7 +600,7 @@ def test_datetimes_multiple_agendas_recurring_subscribed_dates(app):
event = Event.objects.create(
slug='recurring',
start_datetime=now() + datetime.timedelta(days=-15, hours=1),
recurrence_days=[localtime().weekday()],
recurrence_days=[localtime().isoweekday()],
recurrence_end_date=now() + datetime.timedelta(days=15),
places=5,
agenda=agenda,
@ -739,9 +739,9 @@ def test_datetimes_multiple_agendas_shared_custody(app):
)
father_rule = SharedCustodyRule.objects.create(
agenda=agenda, guardian=father, days=list(range(7)), weeks='even'
agenda=agenda, guardian=father, days=list(range(1, 8)), weeks='even'
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='odd')
resp = app.get(
'/api/agendas/datetimes/',
@ -878,8 +878,8 @@ def test_datetimes_multiple_agendas_shared_custody_other_rules(app):
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
father_rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[0, 1, 2])
mother_rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[3, 4, 5, 6])
father_rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[1, 2, 3])
mother_rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[4, 5, 6, 7])
resp = app.get(
'/api/agendas/datetimes/',
@ -895,9 +895,9 @@ def test_datetimes_multiple_agendas_shared_custody_other_rules(app):
assert len(resp.json['data']) == 1
assert resp.json['data'][0]['id'] == 'first-agenda@event-thursday'
father_rule.days = [0, 1]
father_rule.days = [1, 2]
father_rule.save()
other_father_rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[2])
other_father_rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[3])
resp = app.get(
'/api/agendas/datetimes/',
@ -914,7 +914,7 @@ def test_datetimes_multiple_agendas_shared_custody_other_rules(app):
assert resp.json['data'][0]['id'] == 'first-agenda@event-thursday'
other_father_rule.delete()
mother_rule.days = [2, 3, 4, 5, 6]
mother_rule.days = [3, 4, 5, 6, 7]
mother_rule.save()
resp = app.get(
@ -938,7 +938,7 @@ def test_datetimes_multiple_agendas_shared_custody_recurring_event(app):
wednesday_event = Event.objects.create(
slug='event-wednesday',
start_datetime=start_datetime,
recurrence_days=[2],
recurrence_days=[3],
recurrence_end_date=start_datetime + datetime.timedelta(days=30),
places=5,
agenda=event_agenda,
@ -948,7 +948,7 @@ def test_datetimes_multiple_agendas_shared_custody_recurring_event(app):
thursday_event = Event.objects.create(
slug='event-thursday',
start_datetime=start_datetime,
recurrence_days=[3],
recurrence_days=[4],
recurrence_end_date=start_datetime + datetime.timedelta(days=30),
places=5,
agenda=event_agenda,
@ -969,10 +969,10 @@ def test_datetimes_multiple_agendas_shared_custody_recurring_event(app):
)
father_rule = SharedCustodyRule.objects.create(
agenda=agenda, guardian=father, days=list(range(7)), weeks='even'
agenda=agenda, guardian=father, days=list(range(1, 8)), weeks='even'
)
mother_rule = SharedCustodyRule.objects.create(
agenda=agenda, guardian=mother, days=list(range(7)), weeks='odd'
agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='odd'
)
resp = app.get(
@ -1072,13 +1072,13 @@ def test_datetimes_multiple_agendas_shared_custody_recurring_event(app):
]
# weirder rules
father_rule.days = [0, 1]
father_rule.days = [1, 2]
father_rule.weeks = ''
father_rule.save()
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[2])
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[3])
mother_rule.weeks = ''
mother_rule.days = [3, 4, 5, 6]
mother_rule.days = [4, 5, 6, 7]
mother_rule.save()
resp = app.get(
@ -1172,8 +1172,8 @@ def test_datetimes_multiple_agendas_shared_custody_holiday_rules(app):
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='even', guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='odd', guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(1, 8)), weeks='even', guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(1, 8)), weeks='odd', guardian=mother)
resp = app.get(
'/api/agendas/datetimes/',
@ -1243,7 +1243,7 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
wednesday_event = Event.objects.create(
slug='event-wednesday',
start_datetime=start_datetime,
recurrence_days=[2],
recurrence_days=[3],
recurrence_end_date=start_datetime + datetime.timedelta(days=30),
places=5,
agenda=agenda,
@ -1262,7 +1262,7 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)))
resp = app.get(
'/api/agendas/datetimes/',
@ -1289,7 +1289,7 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
child=child,
date_start=datetime.date(year=2022, month=3, day=10),
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)))
resp = app.get(
'/api/agendas/datetimes/',
@ -1317,8 +1317,8 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
child=child,
date_start=datetime.date(year=2022, month=3, day=17),
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='even')
resp = app.get(
'/api/agendas/datetimes/',
@ -1362,8 +1362,10 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
child=child,
date_start=datetime.date(year=2022, month=3, day=22),
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=other_person, days=list(range(7)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='even')
SharedCustodyRule.objects.create(
agenda=agenda, guardian=other_person, days=list(range(1, 8)), weeks='odd'
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='even')
resp = app.get(
'/api/agendas/datetimes/',
@ -1399,7 +1401,7 @@ def test_datetimes_multiple_agendas_shared_custody_date_boundaries(app):
wednesday_event = Event.objects.create(
slug='event-wednesday',
start_datetime=start_datetime,
recurrence_days=[2],
recurrence_days=[3],
recurrence_end_date=datetime.datetime(year=2022, month=5, day=15),
places=5,
agenda=agenda,
@ -1422,7 +1424,7 @@ def test_datetimes_multiple_agendas_shared_custody_date_boundaries(app):
date_start=datetime.datetime(year=2022, month=3, day=15), # 15 days after recurring event start
date_end=datetime.datetime(year=2022, month=3, day=30), # 30 days after recurring event start
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)))
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father,
second_guardian=mother,
@ -1430,7 +1432,7 @@ def test_datetimes_multiple_agendas_shared_custody_date_boundaries(app):
date_start=datetime.datetime(year=2022, month=4, day=13), # 45 days after recurring event start
date_end=datetime.datetime(year=2022, month=4, day=28), # 60 days after recurring event start
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)))
resp = app.get(
'/api/agendas/datetimes/',
@ -1713,7 +1715,7 @@ def test_datetimes_multiple_agendas_enable_full_when_booked(app):
event = Event.objects.create(
slug='recurring',
start_datetime=now() + datetime.timedelta(hours=1),
recurrence_days=[localtime().weekday()],
recurrence_days=[localtime().isoweekday()],
recurrence_end_date=now() + datetime.timedelta(days=15),
places=2,
agenda=agenda,

View File

@ -34,7 +34,7 @@ def test_recurring_events_api_list(app, freezer):
event = Event.objects.create(
label='Example Event',
start_datetime=now(),
recurrence_days=[0, 3, 4], # Monday, Thursday, Friday
recurrence_days=[1, 4, 5], # Monday, Thursday, Friday
places=2,
agenda=agenda,
)
@ -45,7 +45,7 @@ def test_recurring_events_api_list(app, freezer):
Event.objects.create(
label='Other',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
places=2,
agenda=agenda,
recurrence_end_date=now() + datetime.timedelta(days=45),
@ -53,22 +53,22 @@ def test_recurring_events_api_list(app, freezer):
resp = app.get('/api/agendas/recurring-events/?agendas=%s&sort=day' % agenda.slug)
assert len(resp.json['data']) == 4
assert resp.json['data'][0]['id'] == 'foo-bar@example-event:0'
assert resp.json['data'][0]['id'] == 'foo-bar@example-event:1'
assert resp.json['data'][0]['text'] == 'Monday: Example Event'
assert resp.json['data'][0]['label'] == 'Example Event'
assert resp.json['data'][0]['day'] == 'Monday'
assert resp.json['data'][0]['slug'] == 'example-event'
assert resp.json['data'][1]['id'] == 'foo-bar@other:1'
assert resp.json['data'][1]['id'] == 'foo-bar@other:2'
assert resp.json['data'][1]['text'] == 'Tuesday: Other'
assert resp.json['data'][1]['label'] == 'Other'
assert resp.json['data'][1]['day'] == 'Tuesday'
assert resp.json['data'][1]['slug'] == 'other'
assert resp.json['data'][2]['id'] == 'foo-bar@example-event:3'
assert resp.json['data'][2]['id'] == 'foo-bar@example-event:4'
assert resp.json['data'][2]['text'] == 'Thursday: Example Event'
assert resp.json['data'][2]['label'] == 'Example Event'
assert resp.json['data'][2]['day'] == 'Thursday'
assert resp.json['data'][2]['slug'] == 'example-event'
assert resp.json['data'][3]['id'] == 'foo-bar@example-event:4'
assert resp.json['data'][3]['id'] == 'foo-bar@example-event:5'
assert resp.json['data'][3]['text'] == 'Friday: Example Event'
assert resp.json['data'][3]['label'] == 'Example Event'
assert resp.json['data'][3]['day'] == 'Friday'
@ -76,10 +76,10 @@ def test_recurring_events_api_list(app, freezer):
resp = app.get('/api/agendas/recurring-events/?agendas=%s' % agenda.slug)
assert len(resp.json['data']) == 4
assert resp.json['data'][0]['id'] == 'foo-bar@example-event:0'
assert resp.json['data'][1]['id'] == 'foo-bar@example-event:3'
assert resp.json['data'][2]['id'] == 'foo-bar@example-event:4'
assert resp.json['data'][3]['id'] == 'foo-bar@other:1'
assert resp.json['data'][0]['id'] == 'foo-bar@example-event:1'
assert resp.json['data'][1]['id'] == 'foo-bar@example-event:4'
assert resp.json['data'][2]['id'] == 'foo-bar@example-event:5'
assert resp.json['data'][3]['id'] == 'foo-bar@other:2'
resp = app.get('/api/agendas/recurring-events/?agendas=%s&sort=invalid' % agenda.slug, status=400)
assert resp.json['err'] == 1
@ -89,7 +89,7 @@ def test_recurring_events_api_list(app, freezer):
label='New event one hour before',
slug='one-hour-before',
start_datetime=now() - datetime.timedelta(hours=1),
recurrence_days=[3], # Thursday
recurrence_days=[4], # Thursday
places=2,
agenda=agenda,
recurrence_end_date=now() + datetime.timedelta(days=30),
@ -98,18 +98,18 @@ def test_recurring_events_api_list(app, freezer):
label='New event two hours before but one week later',
slug='two-hours-before',
start_datetime=now() + datetime.timedelta(days=6, hours=22),
recurrence_days=[3], # Thursday
recurrence_days=[4], # Thursday
places=2,
agenda=agenda,
)
resp = app.get('/api/agendas/recurring-events/?agendas=%s&sort=day' % agenda.slug)
assert len(resp.json['data']) == 6
assert resp.json['data'][0]['id'] == 'foo-bar@example-event:0'
assert resp.json['data'][1]['id'] == 'foo-bar@other:1'
assert resp.json['data'][2]['id'] == 'foo-bar@two-hours-before:3'
assert resp.json['data'][3]['id'] == 'foo-bar@one-hour-before:3'
assert resp.json['data'][4]['id'] == 'foo-bar@example-event:3'
assert resp.json['data'][5]['id'] == 'foo-bar@example-event:4'
assert resp.json['data'][0]['id'] == 'foo-bar@example-event:1'
assert resp.json['data'][1]['id'] == 'foo-bar@other:2'
assert resp.json['data'][2]['id'] == 'foo-bar@two-hours-before:4'
assert resp.json['data'][3]['id'] == 'foo-bar@one-hour-before:4'
assert resp.json['data'][4]['id'] == 'foo-bar@example-event:4'
assert resp.json['data'][5]['id'] == 'foo-bar@example-event:5'
freezer.move_to(new_event.recurrence_end_date)
resp = app.get('/api/agendas/recurring-events/?agendas=%s' % agenda.slug)
@ -132,7 +132,7 @@ def test_recurring_events_api_list_shared_custody(app):
event = Event.objects.create(
slug='event',
start_datetime=now(),
recurrence_days=[0, 1, 2],
recurrence_days=[1, 2, 3],
recurrence_end_date=now() + datetime.timedelta(days=30),
places=5,
agenda=agenda,
@ -140,7 +140,7 @@ def test_recurring_events_api_list_shared_custody(app):
event.create_all_recurrences()
resp = app.get('/api/agendas/recurring-events/', params={'agendas': agenda.slug})
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2', 'foo-bar@event:3']
# add shared custody agenda
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
@ -150,20 +150,20 @@ def test_recurring_events_api_list_shared_custody(app):
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=father, days=[0], weeks='even')
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=mother, days=[1, 2], weeks='odd')
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=father, days=[1], weeks='even')
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=mother, days=[2, 3], weeks='odd')
resp = app.get(
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'father_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1']
resp = app.get(
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'mother_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:2', 'foo-bar@event:3']
resp = app.get(
'/api/agendas/recurring-events/',
@ -189,14 +189,14 @@ def test_recurring_events_api_list_shared_custody(app):
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'mother_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2', 'foo-bar@event:3']
# nothing changed for father
resp = app.get(
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'father_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1']
# add father custody during holidays
calendar = UnavailabilityCalendar.objects.create(label='Calendar')
@ -221,14 +221,14 @@ def test_recurring_events_api_list_shared_custody(app):
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'father_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2', 'foo-bar@event:3']
# nothing changed for mother
resp = app.get(
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'mother_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2', 'foo-bar@event:3']
# check exceptional custody periods take precedence over holiday rules
SharedCustodyPeriod.objects.create(
@ -243,14 +243,14 @@ def test_recurring_events_api_list_shared_custody(app):
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'father_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:3']
# nothing changed for mother
resp = app.get(
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'mother_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2', 'foo-bar@event:3']
@pytest.mark.freeze_time('2021-12-13 14:00') # Monday of 50th week
@ -262,7 +262,7 @@ def test_recurring_events_api_list_shared_custody_start_date(app):
event = Event.objects.create(
slug='event',
start_datetime=now(),
recurrence_days=[0, 1, 2],
recurrence_days=[1, 2, 3],
recurrence_end_date=now() + datetime.timedelta(days=30),
places=5,
agenda=agenda,
@ -270,7 +270,7 @@ def test_recurring_events_api_list_shared_custody_start_date(app):
event.create_all_recurrences()
resp = app.get('/api/agendas/recurring-events/', params={'agendas': agenda.slug})
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2', 'foo-bar@event:3']
# add shared two custody agendas
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
@ -284,8 +284,8 @@ def test_recurring_events_api_list_shared_custody_start_date(app):
date_start=now(),
date_end=now() + datetime.timedelta(days=14),
)
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=father, days=[0], weeks='even')
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=mother, days=[1, 2], weeks='odd')
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=father, days=[1], weeks='even')
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=mother, days=[2, 3], weeks='odd')
custody_agenda2 = SharedCustodyAgenda.objects.create(
first_guardian=father,
@ -293,20 +293,20 @@ def test_recurring_events_api_list_shared_custody_start_date(app):
child=child,
date_start=now() + datetime.timedelta(days=15),
)
SharedCustodyRule.objects.create(agenda=custody_agenda2, guardian=father, days=[1], weeks='even')
SharedCustodyRule.objects.create(agenda=custody_agenda2, guardian=mother, days=[0, 2], weeks='odd')
SharedCustodyRule.objects.create(agenda=custody_agenda2, guardian=father, days=[2], weeks='even')
SharedCustodyRule.objects.create(agenda=custody_agenda2, guardian=mother, days=[1, 3], weeks='odd')
resp = app.get(
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'father_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2']
resp = app.get(
'/api/agendas/recurring-events/',
params={'agendas': agenda.slug, 'user_external_id': 'child_id', 'guardian_external_id': 'mother_id'},
)
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:0', 'foo-bar@event:1', 'foo-bar@event:2']
assert [x['id'] for x in resp.json['data']] == ['foo-bar@event:1', 'foo-bar@event:2', 'foo-bar@event:3']
@pytest.mark.freeze_time('2021-09-06 12:00')
@ -319,11 +319,11 @@ def test_recurring_events_api_list_multiple_agendas(app):
start_datetime=start,
places=2,
recurrence_end_date=end,
recurrence_days=[0, 2, 5],
recurrence_days=[1, 3, 6],
agenda=agenda,
)
Event.objects.create(
label='B', start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[1], agenda=agenda
label='B', start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[2], agenda=agenda
)
agenda2 = Agenda.objects.create(label='Second Agenda', kind='events')
Desk.objects.create(agenda=agenda2, slug='_exceptions_holder')
@ -332,29 +332,29 @@ def test_recurring_events_api_list_multiple_agendas(app):
start_datetime=start,
places=2,
recurrence_end_date=end,
recurrence_days=[2, 3],
recurrence_days=[3, 4],
agenda=agenda2,
)
resp = app.get('/api/agendas/recurring-events/?agendas=first-agenda,second-agenda&sort=day')
event_ids = [x['id'] for x in resp.json['data']]
assert event_ids == [
'first-agenda@a:0',
'first-agenda@b:1',
'first-agenda@a:2',
'second-agenda@c:2',
'first-agenda@a:1',
'first-agenda@b:2',
'first-agenda@a:3',
'second-agenda@c:3',
'first-agenda@a:5',
'second-agenda@c:4',
'first-agenda@a:6',
]
assert event_ids.index('first-agenda@a:2') < event_ids.index('second-agenda@c:2')
assert event_ids.index('first-agenda@a:3') < event_ids.index('second-agenda@c:3')
# sorting depends on querystring order
resp = app.get('/api/agendas/recurring-events/?agendas=second-agenda,first-agenda&sort=day')
event_ids = [x['id'] for x in resp.json['data']]
assert event_ids.index('first-agenda@a:2') > event_ids.index('second-agenda@c:2')
assert event_ids.index('first-agenda@a:3') > event_ids.index('second-agenda@c:3')
resp = app.get('/api/agendas/recurring-events/?agendas=second-agenda')
assert [x['id'] for x in resp.json['data']] == ['second-agenda@c:2', 'second-agenda@c:3']
assert [x['id'] for x in resp.json['data']] == ['second-agenda@c:3', 'second-agenda@c:4']
@pytest.mark.freeze_time('2021-09-06 12:00')
@ -366,7 +366,7 @@ def test_recurring_events_api_list_multiple_agendas_queries(app):
Desk.objects.create(agenda=agenda, slug='_exceptions_holder')
start, end = now(), now() + datetime.timedelta(days=30)
event = Event.objects.create(
start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[1, 2], agenda=agenda
start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[2, 3], agenda=agenda
)
event.create_all_recurrences()
Subscription.objects.create(
@ -392,8 +392,8 @@ def test_recurring_events_api_list_multiple_agendas_queries(app):
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='odd')
with CaptureQueriesContext(connection) as ctx:
resp = app.get(
@ -412,7 +412,7 @@ def test_recurring_events_api_list_subscribed(app, user):
Event.objects.create(
slug='event',
start_datetime=now(),
recurrence_days=[0, 1, 3, 6], # Monday, Tuesday, Thursday, Friday
recurrence_days=[1, 2, 4, 7], # Monday, Tuesday, Thursday, Friday
places=2,
agenda=first_agenda,
recurrence_end_date=now() + datetime.timedelta(days=364),
@ -420,7 +420,7 @@ def test_recurring_events_api_list_subscribed(app, user):
Event.objects.create(
slug='sunday-event',
start_datetime=now(),
recurrence_days=[5],
recurrence_days=[6],
places=2,
agenda=second_agenda,
recurrence_end_date=now() + datetime.timedelta(days=364),
@ -454,11 +454,11 @@ def test_recurring_events_api_list_subscribed(app, user):
# events are sorted by day
assert [x['id'] for x in resp.json['data']] == [
'first-agenda@event:0',
'first-agenda@event:1',
'first-agenda@event:3',
'second-agenda@sunday-event:5',
'first-agenda@event:6',
'first-agenda@event:2',
'first-agenda@event:4',
'second-agenda@sunday-event:6',
'first-agenda@event:7',
]
resp = app.get('/api/agendas/recurring-events/?user_external_id=xxx&subscribed=category-b')
@ -481,18 +481,18 @@ def test_recurring_events_api_list_subscribed(app, user):
Event.objects.create(
slug='event',
start_datetime=now(),
recurrence_days=[0],
recurrence_days=[1],
places=2,
agenda=second_agenda,
recurrence_end_date=now() + datetime.timedelta(days=364),
)
resp = app.get('/api/agendas/recurring-events/?subscribed=category-a,category-b&user_external_id=xxx')
event_ids = [x['id'] for x in resp.json['data']]
assert event_ids.index('first-agenda@event:0') < event_ids.index('second-agenda@event:0')
assert event_ids.index('first-agenda@event:1') < event_ids.index('second-agenda@event:1')
resp = app.get('/api/agendas/recurring-events/?subscribed=category-b,category-a&user_external_id=xxx')
event_ids = [x['id'] for x in resp.json['data']]
assert event_ids.index('first-agenda@event:0') > event_ids.index('second-agenda@event:0')
assert event_ids.index('first-agenda@event:1') > event_ids.index('second-agenda@event:1')
@pytest.mark.freeze_time('2021-09-06 12:00')
@ -506,7 +506,7 @@ def test_recurring_events_api_list_overlapping_events(app):
duration=120,
places=2,
recurrence_end_date=end,
recurrence_days=[1],
recurrence_days=[2],
agenda=agenda,
).create_all_recurrences()
Event.objects.create(
@ -515,7 +515,7 @@ def test_recurring_events_api_list_overlapping_events(app):
duration=60,
places=2,
recurrence_end_date=end,
recurrence_days=[1],
recurrence_days=[2],
agenda=agenda,
).create_all_recurrences()
Event.objects.create(
@ -524,7 +524,7 @@ def test_recurring_events_api_list_overlapping_events(app):
duration=120,
places=2,
recurrence_end_date=end,
recurrence_days=[1, 3, 5],
recurrence_days=[2, 4, 6],
agenda=agenda,
).create_all_recurrences()
agenda2 = Agenda.objects.create(label='Second Agenda', kind='events')
@ -535,7 +535,7 @@ def test_recurring_events_api_list_overlapping_events(app):
duration=360,
places=2,
recurrence_end_date=end,
recurrence_days=[1, 5],
recurrence_days=[2, 6],
agenda=agenda2,
).create_all_recurrences()
Event.objects.create(
@ -543,7 +543,7 @@ def test_recurring_events_api_list_overlapping_events(app):
start_datetime=start,
places=2,
recurrence_end_date=end,
recurrence_days=[5],
recurrence_days=[6],
agenda=agenda2,
).create_all_recurrences()
@ -556,24 +556,24 @@ def test_recurring_events_api_list_overlapping_events(app):
custody_agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=father, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=father, days=list(range(1, 8)))
params = {'sort': 'day', 'check_overlaps': True, 'user_external_id': 'user_id'}
resp = app.get(
'/api/agendas/recurring-events/', params={'agendas': 'first-agenda,second-agenda', **params}
)
assert [(x['id'], set(x['overlaps'])) for x in resp.json['data']] == [
('first-agenda@event-12-14:1', {'second-agenda@event-12-18:1'}),
('first-agenda@event-12-14:2', {'second-agenda@event-12-18:2'}),
(
'second-agenda@event-12-18:1',
{'first-agenda@event-12-14:1', 'first-agenda@event-14-15:1', 'first-agenda@event-15-17:1'},
'second-agenda@event-12-18:2',
{'first-agenda@event-12-14:2', 'first-agenda@event-14-15:2', 'first-agenda@event-15-17:2'},
),
('first-agenda@event-14-15:1', {'second-agenda@event-12-18:1'}),
('first-agenda@event-15-17:1', {'second-agenda@event-12-18:1'}),
('first-agenda@event-15-17:3', set()),
('second-agenda@event-12-18:5', {'first-agenda@event-15-17:5'}),
('second-agenda@no-duration:5', set()),
('first-agenda@event-15-17:5', {'second-agenda@event-12-18:5'}),
('first-agenda@event-14-15:2', {'second-agenda@event-12-18:2'}),
('first-agenda@event-15-17:2', {'second-agenda@event-12-18:2'}),
('first-agenda@event-15-17:4', set()),
('second-agenda@event-12-18:6', {'first-agenda@event-15-17:6'}),
('second-agenda@no-duration:6', set()),
('first-agenda@event-15-17:6', {'second-agenda@event-12-18:6'}),
]
# same result with shared custody filter
@ -587,11 +587,11 @@ def test_recurring_events_api_list_overlapping_events(app):
resp = app.get('/api/agendas/recurring-events/', params={'agendas': 'first-agenda', **params})
assert [(x['id'], x['overlaps']) for x in resp.json['data']] == [
('first-agenda@event-12-14:1', []),
('first-agenda@event-14-15:1', []),
('first-agenda@event-15-17:1', []),
('first-agenda@event-15-17:3', []),
('first-agenda@event-15-17:5', []),
('first-agenda@event-12-14:2', []),
('first-agenda@event-14-15:2', []),
('first-agenda@event-15-17:2', []),
('first-agenda@event-15-17:4', []),
('first-agenda@event-15-17:6', []),
]
del params['check_overlaps']
@ -613,7 +613,7 @@ def test_recurring_events_api_list_overlapping_events_booking(app, shared_custod
duration=120,
places=2,
recurrence_end_date=end,
recurrence_days=[1, 2],
recurrence_days=[2, 3],
agenda=agenda,
).create_all_recurrences()
event_15_16 = Event.objects.create(
@ -622,7 +622,7 @@ def test_recurring_events_api_list_overlapping_events_booking(app, shared_custod
duration=60,
places=2,
recurrence_end_date=end,
recurrence_days=[1],
recurrence_days=[2],
agenda=agenda,
)
event_15_16.create_all_recurrences()
@ -634,7 +634,7 @@ def test_recurring_events_api_list_overlapping_events_booking(app, shared_custod
duration=120,
places=2,
recurrence_end_date=end,
recurrence_days=[1, 2],
recurrence_days=[2, 3],
agenda=second_agenda,
)
event_13_15.create_all_recurrences()
@ -647,7 +647,7 @@ def test_recurring_events_api_list_overlapping_events_booking(app, shared_custod
custody_agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=father, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=custody_agenda, guardian=father, days=list(range(1, 8)))
params = {
'sort': 'day',
@ -661,11 +661,11 @@ def test_recurring_events_api_list_overlapping_events_booking(app, shared_custod
params['agendas'] = 'first-agenda'
resp = app.get('/api/agendas/recurring-events/', params=params)
assert len(resp.json['data']) == 3
assert resp.json['data'][0]['id'] == 'first-agenda@event-12-14:1'
assert resp.json['data'][0]['id'] == 'first-agenda@event-12-14:2'
assert resp.json['data'][0]['has_booking_overlaps'] is False
assert resp.json['data'][1]['id'] == 'first-agenda@event-15-16:1'
assert resp.json['data'][1]['id'] == 'first-agenda@event-15-16:2'
assert resp.json['data'][1]['has_booking_overlaps'] is False
assert resp.json['data'][2]['id'] == 'first-agenda@event-12-14:2'
assert resp.json['data'][2]['id'] == 'first-agenda@event-12-14:3'
assert resp.json['data'][2]['has_booking_overlaps'] is False
# create one booking on first day
@ -674,11 +674,11 @@ def test_recurring_events_api_list_overlapping_events_booking(app, shared_custod
resp = app.get('/api/agendas/recurring-events/', params=params)
assert len(resp.json['data']) == 3
assert resp.json['data'][0]['id'] == 'first-agenda@event-12-14:1'
assert resp.json['data'][0]['id'] == 'first-agenda@event-12-14:2'
assert resp.json['data'][0]['has_booking_overlaps'] is True
assert resp.json['data'][1]['id'] == 'first-agenda@event-15-16:1'
assert resp.json['data'][1]['id'] == 'first-agenda@event-15-16:2'
assert resp.json['data'][1]['has_booking_overlaps'] is False
assert resp.json['data'][2]['id'] == 'first-agenda@event-12-14:2'
assert resp.json['data'][2]['id'] == 'first-agenda@event-12-14:3'
assert resp.json['data'][2]['has_booking_overlaps'] is False
# create one booking on second day
@ -687,11 +687,11 @@ def test_recurring_events_api_list_overlapping_events_booking(app, shared_custod
resp = app.get('/api/agendas/recurring-events/', params=params)
assert len(resp.json['data']) == 3
assert resp.json['data'][0]['id'] == 'first-agenda@event-12-14:1'
assert resp.json['data'][0]['id'] == 'first-agenda@event-12-14:2'
assert resp.json['data'][0]['has_booking_overlaps'] is True
assert resp.json['data'][1]['id'] == 'first-agenda@event-15-16:1'
assert resp.json['data'][1]['id'] == 'first-agenda@event-15-16:2'
assert resp.json['data'][1]['has_booking_overlaps'] is False
assert resp.json['data'][2]['id'] == 'first-agenda@event-12-14:2'
assert resp.json['data'][2]['id'] == 'first-agenda@event-12-14:3'
assert resp.json['data'][2]['has_booking_overlaps'] is True
# create one booking on first agenda
@ -700,11 +700,11 @@ def test_recurring_events_api_list_overlapping_events_booking(app, shared_custod
resp = app.get('/api/agendas/recurring-events/', params=params)
assert len(resp.json['data']) == 3
assert resp.json['data'][0]['id'] == 'first-agenda@event-12-14:1'
assert resp.json['data'][0]['id'] == 'first-agenda@event-12-14:2'
assert resp.json['data'][0]['has_booking_overlaps'] is True
assert resp.json['data'][1]['id'] == 'first-agenda@event-15-16:1'
assert resp.json['data'][1]['id'] == 'first-agenda@event-15-16:2'
assert resp.json['data'][1]['has_booking_overlaps'] is False # event is not marked as overlapping
assert resp.json['data'][2]['id'] == 'first-agenda@event-12-14:2'
assert resp.json['data'][2]['id'] == 'first-agenda@event-12-14:3'
assert resp.json['data'][2]['has_booking_overlaps'] is True
# check date start

View File

@ -385,7 +385,7 @@ def test_booking_api_exclude_slots(app, user):
event = Event.objects.create(
slug='recurrent',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=15),
places=3,
agenda=agenda,
@ -2433,7 +2433,7 @@ def test_fillslot_past_events_recurring_event(app, user):
event = Event.objects.create(
label='Recurring',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=now() + datetime.timedelta(days=30),
places=5,
agenda=agenda,
@ -2546,7 +2546,7 @@ def test_fillslot_recurring_event_booking_forbidden(app, user):
event = Event.objects.create(
label='Event',
start_datetime=now() + datetime.timedelta(days=7),
recurrence_days=[now().weekday()],
recurrence_days=[now().isoweekday()],
places=2,
agenda=agenda,
)

View File

@ -625,8 +625,8 @@ def test_api_events_fillslots_multiple_agendas_shared_custody(app, user):
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[0, 1, 2])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[3, 4, 5, 6])
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[1, 2, 3])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[4, 5, 6, 7])
app.authorization = ('Basic', ('john.doe', 'password'))
params = {'user_external_id': 'child_id', 'slots': 'first-agenda@event-wednesday'}
@ -702,7 +702,7 @@ def test_api_events_fillslots_multiple_agendas_shared_custody_date_start(app, us
date_start=now(),
date_end=datetime.date(year=2022, month=3, day=9),
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)))
agenda2 = SharedCustodyAgenda.objects.create(
first_guardian=father,
@ -710,7 +710,7 @@ def test_api_events_fillslots_multiple_agendas_shared_custody_date_start(app, us
child=child,
date_start=datetime.date(year=2022, month=3, day=10),
)
SharedCustodyRule.objects.create(agenda=agenda2, guardian=mother, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=agenda2, guardian=mother, days=list(range(1, 8)))
app.authorization = ('Basic', ('john.doe', 'password'))
params = {'user_external_id': 'child_id', 'slots': 'first-agenda@event-wednesday'}

View File

@ -36,7 +36,7 @@ def test_recurring_events_api_fillslots(app, user, freezer, action):
event = Event.objects.create(
label='Event',
start_datetime=now(),
recurrence_days=[0, 1, 3, 4], # Monday, Tuesday, Thursday, Friday
recurrence_days=[1, 2, 4, 5], # Monday, Tuesday, Thursday, Friday
places=2,
waiting_list_places=1,
agenda=agenda,
@ -46,7 +46,7 @@ def test_recurring_events_api_fillslots(app, user, freezer, action):
sunday_event = Event.objects.create(
label='Sunday Event',
start_datetime=now(),
recurrence_days=[6],
recurrence_days=[7],
places=2,
waiting_list_places=1,
agenda=agenda,
@ -61,7 +61,7 @@ def test_recurring_events_api_fillslots(app, user, freezer, action):
fillslots_url = '/api/agendas/recurring-events/fillslots/?agendas=%s&action=%s' % (agenda.slug, action)
params = {'user_external_id': 'user_id'}
# Book Monday and Thursday of first event and Sunday of second event
params['slots'] = 'foo-bar@event:0,foo-bar@event:3,foo-bar@sunday-event:6'
params['slots'] = 'foo-bar@event:1,foo-bar@event:4,foo-bar@sunday-event:7'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 3
assert 'booked_events' not in resp.json
@ -124,7 +124,7 @@ def test_recurring_events_api_fillslots(app, user, freezer, action):
resp = app.post_json(fillslots_url + '&date_start=2020-09-13&date_end=2020-09-19', params=params)
assert resp.json['booking_count'] == 0
params['slots'] = 'foo-bar@event:1'
params['slots'] = 'foo-bar@event:2'
params['include_booked_events_detail'] = True
resp = app.post_json(fillslots_url + '&date_start=2021-09-13&date_end=2021-09-19', params=params)
assert resp.json['booking_count'] == 1
@ -136,7 +136,7 @@ def test_recurring_events_api_fillslots(app, user, freezer, action):
== Booking.objects.filter(user_external_id='user_id_4').get().pk
)
resp = app.post_json(fillslots_url, params={'slots': 'foo-bar@event:0'}, status=400)
resp = app.post_json(fillslots_url, params={'slots': 'foo-bar@event:1'}, status=400)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'invalid payload'
assert resp.json['errors']['user_external_id'] == ['This field is required.']
@ -150,7 +150,7 @@ def test_recurring_events_api_fillslots(app, user, freezer, action):
assert resp.json['err'] == 1
assert resp.json['errors']['slots'] == ['invalid slot: foo-bar@a:a']
resp = app.post_json(fillslots_url, params={'user_external_id': 'a', 'slots': 'foo-bar@a:1'}, status=400)
resp = app.post_json(fillslots_url, params={'user_external_id': 'a', 'slots': 'foo-bar@a:2'}, status=400)
assert resp.json['err'] == 1
assert resp.json['errors']['slots'] == ['event a of agenda foo-bar is not bookable']
@ -171,7 +171,7 @@ def test_recurring_events_api_fillslots(app, user, freezer, action):
params = {
'user_external_id': 'user_id',
'slots': 'foo-bar@event:1',
'slots': 'foo-bar@event:2',
'foo': 'bar',
}
resp = app.post_json(fillslots_url, params=params)
@ -198,7 +198,7 @@ def test_recurring_events_api_fillslots_waiting_list(app, user, freezer):
event = Event.objects.create(
label='Event',
start_datetime=now(),
recurrence_days=[0],
recurrence_days=[1],
places=2,
waiting_list_places=2,
agenda=agenda,
@ -214,7 +214,7 @@ def test_recurring_events_api_fillslots_waiting_list(app, user, freezer):
assert events.filter(booked_waiting_list_places=1).count() == 5
# check that new bookings are put in waiting list despite free slots on main list
params = {'user_external_id': 'user_id', 'slots': 'foo-bar@event:0'}
params = {'user_external_id': 'user_id', 'slots': 'foo-bar@event:1'}
resp = app.post_json(
'/api/agendas/recurring-events/fillslots/?agendas=%s&action=update' % agenda.slug, params=params
)
@ -229,7 +229,7 @@ def test_recurring_events_api_fillslots_book_with_cancelled(app, user, freezer):
event = Event.objects.create(
label='Event',
start_datetime=now(),
recurrence_days=[0, 1], # Monday, Tuesday
recurrence_days=[1, 2], # Monday, Tuesday
places=1,
waiting_list_places=1,
agenda=agenda,
@ -269,7 +269,7 @@ def test_recurring_events_api_fillslots_book_with_cancelled(app, user, freezer):
params = {'user_external_id': 'user_id'}
# Book Monday
params['slots'] = 'foo-bar@event:0'
params['slots'] = 'foo-bar@event:1'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 2
assert resp.json['cancelled_booking_count'] == 0
@ -303,7 +303,7 @@ def test_recurring_events_api_fillslots_book_with_cancelled(app, user, freezer):
assert booking_2_1.cancellation_datetime is None
# Book Tuesday
params['slots'] = 'foo-bar@event:1'
params['slots'] = 'foo-bar@event:2'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 2
assert resp.json['cancelled_booking_count'] == 0
@ -345,7 +345,7 @@ def test_recurring_events_api_fillslots_update(app, user, freezer):
event = Event.objects.create(
label='Event',
start_datetime=now(),
recurrence_days=[0, 1, 3, 4], # Monday, Tuesday, Thursday, Friday
recurrence_days=[1, 2, 4, 5], # Monday, Tuesday, Thursday, Friday
places=1,
waiting_list_places=1,
agenda=agenda,
@ -357,7 +357,7 @@ def test_recurring_events_api_fillslots_update(app, user, freezer):
fillslots_url = '/api/agendas/recurring-events/fillslots/?agendas=%s&action=update' % agenda.slug
params = {'user_external_id': 'user_id'}
# Book Monday and Thursday
params['slots'] = 'foo-bar@event:0,foo-bar@event:3'
params['slots'] = 'foo-bar@event:1,foo-bar@event:4'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 8
assert resp.json['cancelled_booking_count'] == 0
@ -366,7 +366,7 @@ def test_recurring_events_api_fillslots_update(app, user, freezer):
assert Booking.objects.filter(event__start_datetime__week_day=5).count() == 4
# Book Friday without changing other bookings
params['slots'] = 'foo-bar@event:4'
params['slots'] = 'foo-bar@event:5'
resp = app.post_json(fillslots_url.replace('update', 'book'), params=params)
assert resp.json['booking_count'] == 4
assert resp.json['cancelled_booking_count'] == 0
@ -381,7 +381,7 @@ def test_recurring_events_api_fillslots_update(app, user, freezer):
agenda.save()
# Change booking to Monday and Tuesday
params['slots'] = 'foo-bar@event:0,foo-bar@event:1'
params['slots'] = 'foo-bar@event:1,foo-bar@event:2'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 2
assert resp.json['cancelled_booking_count'] == 4
@ -446,7 +446,7 @@ def test_recurring_events_api_fillslots_update(app, user, freezer):
assert Booking.objects.filter(cancellation_datetime__isnull=True).count() == 8
params = {'user_external_id': 'user_id_2'}
params['slots'] = 'foo-bar@event:0,foo-bar@event:3'
params['slots'] = 'foo-bar@event:1,foo-bar@event:4'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 8
assert resp.json['cancelled_booking_count'] == 0
@ -476,7 +476,7 @@ def test_recurring_events_api_fillslots_update(app, user, freezer):
assert events.filter(booked_places=1).count() == 12
assert events.filter(booked_waiting_list_places=1).count() == 4
params['slots'] = 'foo-bar@event:1,foo-bar@event:4'
params['slots'] = 'foo-bar@event:2,foo-bar@event:5'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 8
assert resp.json['cancelled_booking_count'] == 8
@ -556,7 +556,7 @@ def test_recurring_events_api_fillslots_update(app, user, freezer):
start_datetime=now() + datetime.timedelta(days=1), places=2, agenda=agenda
)
Booking.objects.create(event=normal_event, user_external_id='user_id')
resp = app.post_json(fillslots_url, params={'user_external_id': 'user_id', 'slots': 'foo-bar@event:0'})
resp = app.post_json(fillslots_url, params={'user_external_id': 'user_id', 'slots': 'foo-bar@event:1'})
assert resp.json['cancelled_booking_count'] == 3
assert Booking.objects.filter(user_external_id='user_id', event=normal_event).count() == 1
@ -568,7 +568,7 @@ def test_recurring_events_api_fillslots_update_with_cancelled(app, user, freezer
event = Event.objects.create(
label='Event',
start_datetime=now(),
recurrence_days=[0, 1], # Monday, Tuesday
recurrence_days=[1, 2], # Monday, Tuesday
places=1,
waiting_list_places=1,
agenda=agenda,
@ -610,7 +610,7 @@ def test_recurring_events_api_fillslots_update_with_cancelled(app, user, freezer
params = {'user_external_id': 'user_id'}
# Book Monday
params['slots'] = 'foo-bar@event:0'
params['slots'] = 'foo-bar@event:1'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 2
assert resp.json['cancelled_booking_count'] == 1
@ -648,7 +648,7 @@ def test_recurring_events_api_fillslots_update_with_cancelled(app, user, freezer
assert booking_2_1_secondary.cancellation_datetime is not None
# Book Tuesday
params['slots'] = 'foo-bar@event:1'
params['slots'] = 'foo-bar@event:2'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 3
assert resp.json['cancelled_booking_count'] == 3
@ -690,7 +690,7 @@ def test_recurring_events_api_fillslots_unbook(app, user, freezer):
event = Event.objects.create(
label='Event',
start_datetime=now(),
recurrence_days=[0, 1, 3, 4], # Monday, Tuesday, Thursday, Friday
recurrence_days=[1, 2, 4, 5], # Monday, Tuesday, Thursday, Friday
places=2,
waiting_list_places=1,
agenda=agenda,
@ -700,7 +700,7 @@ def test_recurring_events_api_fillslots_unbook(app, user, freezer):
sunday_event = Event.objects.create(
label='Sunday Event',
start_datetime=now(),
recurrence_days=[6],
recurrence_days=[7],
places=2,
waiting_list_places=1,
agenda=agenda,
@ -711,7 +711,7 @@ def test_recurring_events_api_fillslots_unbook(app, user, freezer):
app.authorization = ('Basic', ('john.doe', 'password'))
fillslots_url = '/api/agendas/recurring-events/fillslots/?agendas=%s' % agenda.slug
params = {'user_external_id': 'user_id'}
params['slots'] = 'foo-bar@event:0,foo-bar@event:3,foo-bar@sunday-event:6'
params['slots'] = 'foo-bar@event:1,foo-bar@event:4,foo-bar@sunday-event:7'
resp = app.post_json(fillslots_url + '&action=book', params=params)
assert resp.json['booking_count'] == 12
@ -724,7 +724,7 @@ def test_recurring_events_api_fillslots_unbook(app, user, freezer):
agenda.maximal_booking_delay = 21
agenda.save()
params['slots'] = 'foo-bar@event:0'
params['slots'] = 'foo-bar@event:1'
resp = app.post_json(fillslots_url + '&action=unbook', params=params)
assert resp.json['booking_count'] == 0
assert resp.json['cancelled_booking_count'] == 2
@ -777,7 +777,7 @@ def test_recurring_events_api_fillslots_unbook(app, user, freezer):
== 4
)
params['slots'] = 'foo-bar@sunday-event:6'
params['slots'] = 'foo-bar@sunday-event:7'
resp = app.post_json(
fillslots_url + '&action=unbook&date_start=2021-09-13&date_end=2021-09-20', params=params
)
@ -824,7 +824,7 @@ def test_recurring_events_api_fillslots_unbook(app, user, freezer):
freezer.move_to('2021-09-13 12:00')
# old bookings are not unbooked
params['slots'] = 'foo-bar@event:3'
params['slots'] = 'foo-bar@event:4'
resp = app.post_json(fillslots_url + '&action=unbook', params=params)
assert resp.json['booking_count'] == 0
assert resp.json['cancelled_booking_count'] == 3
@ -864,7 +864,7 @@ def test_recurring_events_api_fillslots_unbook_with_cancelled(app, user, freezer
event = Event.objects.create(
label='Event',
start_datetime=now(),
recurrence_days=[0, 1], # Monday, Tuesday
recurrence_days=[1, 2], # Monday, Tuesday
places=1,
waiting_list_places=1,
agenda=agenda,
@ -904,7 +904,7 @@ def test_recurring_events_api_fillslots_unbook_with_cancelled(app, user, freezer
params = {'user_external_id': 'user_id'}
# unbook Monday
params['slots'] = 'foo-bar@event:0'
params['slots'] = 'foo-bar@event:1'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 0
assert resp.json['cancelled_booking_count'] == 1
@ -939,7 +939,7 @@ def test_recurring_events_api_fillslots_unbook_with_cancelled(app, user, freezer
assert booking_2_1.cancellation_datetime is None
# unbook Tuesday
params['slots'] = 'foo-bar@event:1'
params['slots'] = 'foo-bar@event:2'
resp = app.post_json(fillslots_url, params=params)
assert resp.json['booking_count'] == 0
assert resp.json['cancelled_booking_count'] == 1
@ -997,7 +997,7 @@ def test_recurring_events_api_fillslots_subscribed(app, user):
event = Event.objects.create(
slug='event',
start_datetime=now(),
recurrence_days=[0, 1, 3, 4], # Monday, Tuesday, Thursday, Friday
recurrence_days=[1, 2, 4, 5], # Monday, Tuesday, Thursday, Friday
places=2,
waiting_list_places=1,
agenda=first_agenda,
@ -1007,7 +1007,7 @@ def test_recurring_events_api_fillslots_subscribed(app, user):
sunday_event = Event.objects.create(
slug='sunday-event',
start_datetime=now(),
recurrence_days=[6],
recurrence_days=[7],
places=2,
waiting_list_places=1,
agenda=second_agenda,
@ -1026,7 +1026,7 @@ def test_recurring_events_api_fillslots_subscribed(app, user):
fillslots_url = '/api/agendas/recurring-events/fillslots/?action=update&subscribed=%s'
params = {'user_external_id': 'xxx'}
# book Monday and Thursday of first event, in subscription range
params['slots'] = 'first-agenda@event:0,first-agenda@event:3'
params['slots'] = 'first-agenda@event:1,first-agenda@event:4'
resp = app.post_json(fillslots_url % 'category-a', params=params)
assert resp.json['booking_count'] == 9
assert Booking.objects.count() == 9
@ -1098,7 +1098,7 @@ def test_recurring_events_api_fillslots_subscribed(app, user):
)
# not subscribed category
params['slots'] = 'second-agenda@sunday-event:6'
params['slots'] = 'second-agenda@sunday-event:7'
resp = app.post_json(fillslots_url % 'category-b', params=params, status=400)
# update bookings
@ -1108,7 +1108,7 @@ def test_recurring_events_api_fillslots_subscribed(app, user):
date_start=now() + datetime.timedelta(days=100), # Wednesday 15/12
date_end=now() + datetime.timedelta(days=150), # Thursday 03/02
)
params['slots'] = 'first-agenda@event:1,second-agenda@sunday-event:6'
params['slots'] = 'first-agenda@event:2,second-agenda@sunday-event:7'
resp = app.post_json(fillslots_url % 'all', params=params)
assert resp.json['booking_count'] == 12
assert resp.json['cancelled_booking_count'] == 10
@ -1144,7 +1144,7 @@ def test_recurring_events_api_fillslots_subscribed(app, user):
date_start=now() + datetime.timedelta(days=60),
date_end=now() + datetime.timedelta(days=70),
)
params = {'user_external_id': 'yyy', 'slots': 'second-agenda@sunday-event:6'}
params = {'user_external_id': 'yyy', 'slots': 'second-agenda@sunday-event:7'}
resp = app.post_json(fillslots_url % 'category-b', params=params)
assert resp.json['booking_count'] == 3
assert Booking.objects.filter(cancellation_datetime__isnull=True).count() == 15
@ -1170,12 +1170,12 @@ def test_recurring_events_api_fillslots_multiple_agendas(app, user):
start_datetime=start,
places=2,
recurrence_end_date=end,
recurrence_days=[0, 2, 5],
recurrence_days=[1, 3, 6],
agenda=agenda,
)
event_a.create_all_recurrences()
event_b = Event.objects.create(
label='B', start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[1], agenda=agenda
label='B', start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[2], agenda=agenda
)
event_b.create_all_recurrences()
agenda2 = Agenda.objects.create(label='Second Agenda', kind='events')
@ -1185,7 +1185,7 @@ def test_recurring_events_api_fillslots_multiple_agendas(app, user):
start_datetime=start,
places=2,
recurrence_end_date=end,
recurrence_days=[2, 3],
recurrence_days=[3, 4],
agenda=agenda2,
)
event_c.create_all_recurrences()
@ -1195,7 +1195,7 @@ def test_recurring_events_api_fillslots_multiple_agendas(app, user):
app.authorization = ('Basic', ('john.doe', 'password'))
fillslots_url = '/api/agendas/recurring-events/fillslots/?action=%s&agendas=%s'
params = {'user_external_id': 'user_id', 'slots': 'first-agenda@a:0,first-agenda@a:5,second-agenda@c:3'}
params = {'user_external_id': 'user_id', 'slots': 'first-agenda@a:1,first-agenda@a:6,second-agenda@c:4'}
resp = app.post_json(fillslots_url % ('update', 'first-agenda,second-agenda'), params=params)
assert resp.json['booking_count'] == 13
@ -1205,7 +1205,7 @@ def test_recurring_events_api_fillslots_multiple_agendas(app, user):
assert Booking.objects.filter(event__primary_event=event_c).count() == 4
# add bookings
params = {'user_external_id': 'user_id', 'slots': 'first-agenda@a:2,second-agenda@c:2'}
params = {'user_external_id': 'user_id', 'slots': 'first-agenda@a:3,second-agenda@c:3'}
resp = app.post_json(fillslots_url % ('book', 'first-agenda,second-agenda'), params=params)
assert resp.json['booking_count'] == 8
assert resp.json['cancelled_booking_count'] == 0
@ -1216,7 +1216,7 @@ def test_recurring_events_api_fillslots_multiple_agendas(app, user):
assert Booking.objects.filter(event__primary_event=event_c).count() == 8
# unbook last week bookings
params = {'user_external_id': 'user_id', 'slots': 'first-agenda@a:2,second-agenda@c:2'}
params = {'user_external_id': 'user_id', 'slots': 'first-agenda@a:3,second-agenda@c:3'}
date_start_param = '&date_start=%s' % (end - datetime.timedelta(days=7)).strftime('%Y-%m-%d')
resp = app.post_json(
(fillslots_url % ('unbook', 'first-agenda,second-agenda')) + date_start_param, params=params
@ -1248,7 +1248,7 @@ def test_recurring_events_api_fillslots_multiple_agendas(app, user):
)
# update bookings
params = {'user_external_id': 'user_id', 'slots': 'first-agenda@b:1'}
params = {'user_external_id': 'user_id', 'slots': 'first-agenda@b:2'}
resp = app.post_json(fillslots_url % ('update', 'first-agenda,second-agenda'), params=params)
assert resp.json['booking_count'] == 5
@ -1291,7 +1291,7 @@ def test_recurring_events_api_fillslots_multiple_agendas_queries(app, user):
Desk.objects.create(agenda=agenda, slug='_exceptions_holder')
start, end = now(), now() + datetime.timedelta(days=30)
event = Event.objects.create(
start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[1, 2], agenda=agenda
start_datetime=start, places=2, recurrence_end_date=end, recurrence_days=[2, 3], agenda=agenda
)
event.create_all_recurrences()
with connection.cursor() as cursor:
@ -1338,8 +1338,8 @@ def test_recurring_events_api_fillslots_multiple_agendas_queries(app, user):
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='odd')
with CaptureQueriesContext(connection) as ctx:
resp = app.post_json(
@ -1358,7 +1358,7 @@ def test_recurring_events_api_fillslots_shared_custody(app, user, freezer):
event = Event.objects.create(
label='Event',
start_datetime=now(),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=2,
waiting_list_places=1,
agenda=agenda,
@ -1373,11 +1373,11 @@ def test_recurring_events_api_fillslots_shared_custody(app, user, freezer):
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, weeks='odd', days=[0, 1, 2])
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, weeks='even', days=[3, 4, 5])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, weeks='even', days=[0, 1, 2])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, weeks='odd', days=[3, 4, 5])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[6])
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, weeks='odd', days=[1, 2, 3])
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, weeks='even', days=[4, 5, 6])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, weeks='even', days=[1, 2, 3])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, weeks='odd', days=[4, 5, 6])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[7])
app.authorization = ('Basic', ('john.doe', 'password'))
fillslots_url = (
@ -1385,7 +1385,7 @@ def test_recurring_events_api_fillslots_shared_custody(app, user, freezer):
)
params = {
'user_external_id': 'child_id',
'slots': ','.join('foo-bar@event:%s' % i for i in range(7)), # book every days
'slots': ','.join('foo-bar@event:%s' % i for i in range(1, 8)), # book every days
'include_booked_events_detail': True,
}
resp = app.post_json(fillslots_url % 'father_id', params=params)
@ -1422,7 +1422,7 @@ def test_recurring_events_api_fillslots_shared_custody(app, user, freezer):
date_start=datetime.date(year=2022, month=3, day=14),
)
SharedCustodyRule.objects.create(agenda=agenda2, guardian=father, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=agenda2, guardian=father, days=list(range(1, 8)))
Booking.objects.all().delete()
resp = app.post_json(fillslots_url % 'father_id', params=params)
@ -1473,7 +1473,7 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
duration=120,
places=2,
recurrence_end_date=end,
recurrence_days=[1],
recurrence_days=[2],
agenda=agenda,
).create_all_recurrences()
Event.objects.create(
@ -1482,7 +1482,7 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
duration=60,
places=2,
recurrence_end_date=end,
recurrence_days=[1],
recurrence_days=[2],
agenda=agenda,
).create_all_recurrences()
Event.objects.create(
@ -1491,7 +1491,7 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
duration=120,
places=2,
recurrence_end_date=end,
recurrence_days=[1, 3, 5],
recurrence_days=[2, 4, 6],
agenda=agenda,
).create_all_recurrences()
agenda2 = Agenda.objects.create(label='Second Agenda', kind='events')
@ -1502,7 +1502,7 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
duration=360,
places=2,
recurrence_end_date=end,
recurrence_days=[1, 5],
recurrence_days=[2, 6],
agenda=agenda2,
).create_all_recurrences()
Event.objects.create(
@ -1510,7 +1510,7 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
start_datetime=start,
places=2,
recurrence_end_date=end,
recurrence_days=[5],
recurrence_days=[6],
agenda=agenda2,
).create_all_recurrences()
@ -1521,7 +1521,7 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
params = {
'user_external_id': 'user_id',
'check_overlaps': 'first-agenda,second-agenda',
'slots': 'first-agenda@event-12-14:1,first-agenda@event-14-15:1,second-agenda@event-12-18:5',
'slots': 'first-agenda@event-12-14:2,first-agenda@event-14-15:2,second-agenda@event-12-18:6',
}
resp = app.post_json(fillslots_url % ('update', 'first-agenda,second-agenda'), params=params)
assert resp.json['booking_count'] == 14
@ -1534,7 +1534,7 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
params = {
'user_external_id': 'user_id',
'check_overlaps': 'first-agenda,second-agenda',
'slots': 'second-agenda@event-12-18:1',
'slots': 'second-agenda@event-12-18:2',
}
resp = app.post_json(fillslots_url % ('update', 'first-agenda,second-agenda'), params=params)
assert resp.json['booking_count'] == 5
@ -1546,7 +1546,7 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
params = {
'user_external_id': 'user_id',
'check_overlaps': 'first-agenda,second-agenda',
'slots': 'second-agenda@event-12-18:5,second-agenda@no-duration:5',
'slots': 'second-agenda@event-12-18:6,second-agenda@no-duration:6',
'include_booked_events_detail': True,
}
resp = app.post_json(fillslots_url % ('update', 'first-agenda,second-agenda'), params=params)
@ -1574,34 +1574,34 @@ def test_recurring_events_api_fillslots_overlapping_events(app, user):
params = {
'user_external_id': 'user_id',
'check_overlaps': 'first-agenda,second-agenda',
'slots': 'first-agenda@event-12-14:1,second-agenda@event-12-18:1',
'slots': 'first-agenda@event-12-14:2,second-agenda@event-12-18:2',
}
resp = app.post_json(fillslots_url % ('update', 'first-agenda,second-agenda'), params=params)
assert resp.json['err'] == 1
assert (
resp.json['err_desc']
== 'Some events occur at the same time: first-agenda@event-12-14:1 / second-agenda@event-12-18:1'
== 'Some events occur at the same time: first-agenda@event-12-14:2 / second-agenda@event-12-18:2'
)
params = {
'user_external_id': 'user_id',
'check_overlaps': 'first-agenda,second-agenda',
'slots': (
'first-agenda@event-12-14:1,first-agenda@event-15-17:1,first-agenda@event-15-17:3,first-agenda@event-15-17:5,second-agenda@event-12-18:1,'
'second-agenda@event-12-18:5,second-agenda@no-duration:5'
'first-agenda@event-12-14:2,first-agenda@event-15-17:2,first-agenda@event-15-17:4,first-agenda@event-15-17:6,second-agenda@event-12-18:2,'
'second-agenda@event-12-18:6,second-agenda@no-duration:6'
),
}
resp = app.post_json(fillslots_url % ('update', 'first-agenda,second-agenda'), params=params)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == (
'Some events occur at the same time: first-agenda@event-12-14:1 / second-agenda@event-12-18:1, '
'first-agenda@event-15-17:1 / second-agenda@event-12-18:1, first-agenda@event-15-17:5 / second-agenda@event-12-18:5'
'Some events occur at the same time: first-agenda@event-12-14:2 / second-agenda@event-12-18:2, '
'first-agenda@event-15-17:2 / second-agenda@event-12-18:2, first-agenda@event-15-17:6 / second-agenda@event-12-18:6'
)
# overlaps check is disabled by default
params = {
'user_external_id': 'user_id',
'slots': 'first-agenda@event-12-14:1,second-agenda@event-12-18:1',
'slots': 'first-agenda@event-12-14:2,second-agenda@event-12-18:2',
}
resp = app.post_json(fillslots_url % ('update', 'first-agenda,second-agenda'), params=params)
assert resp.json['err'] == 0
@ -1619,7 +1619,7 @@ def test_recurring_events_api_fillslots_partly_overlapping_events(app, user):
duration=120,
places=2,
recurrence_end_date=end + datetime.timedelta(days=7),
recurrence_days=[1],
recurrence_days=[2],
agenda=agenda,
)
event_12_14.create_all_recurrences()
@ -1631,7 +1631,7 @@ def test_recurring_events_api_fillslots_partly_overlapping_events(app, user):
duration=120,
places=2,
recurrence_end_date=end,
recurrence_days=[1],
recurrence_days=[2],
agenda=agenda2,
).create_all_recurrences()
@ -1645,7 +1645,7 @@ def test_recurring_events_api_fillslots_partly_overlapping_events(app, user):
params = {
'user_external_id': 'user_id',
'check_overlaps': 'first-agenda,second-agenda',
'slots': 'second-agenda@event-13-15:1',
'slots': 'second-agenda@event-13-15:2',
'include_booked_events_detail': True,
}
resp = app.post_json(fillslots_url % 'second-agenda', params=params)
@ -1659,7 +1659,7 @@ def test_recurring_events_api_fillslots_partly_overlapping_events(app, user):
'2021-10-05',
]
params['slots'] = 'first-agenda@event-12-14:1'
params['slots'] = 'first-agenda@event-12-14:2'
resp = app.post_json(fillslots_url % 'first-agenda', params=params)
assert resp.json['booking_count'] == 1
assert resp.json['cancelled_booking_count'] == 0
@ -1690,7 +1690,7 @@ def test_recurring_events_api_fillslots_partial_bookings(app, user):
end_time=datetime.time(18, 00),
places=2,
recurrence_end_date=start_datetime + datetime.timedelta(days=30),
recurrence_days=[1],
recurrence_days=[2],
agenda=agenda,
)
event.create_all_recurrences()
@ -1699,7 +1699,7 @@ def test_recurring_events_api_fillslots_partial_bookings(app, user):
params = {
'user_external_id': 'user_id',
'slots': 'foo-bar@event-08-18:1',
'slots': 'foo-bar@event-08-18:2',
'start_time': '10:00',
'end_time': '15:00',
}

View File

@ -288,7 +288,7 @@ def test_agendas_api(app):
start_datetime=now(),
places=10,
agenda=event_agenda,
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
recurrence_end_date=now() + datetime.timedelta(days=15),
)
event.create_all_recurrences()
@ -304,7 +304,7 @@ def test_agendas_api(app):
start_datetime=now(),
places=10,
agenda=event_agenda,
recurrence_days=[now().weekday()],
recurrence_days=[now().isoweekday()],
recurrence_end_date=now() + datetime.timedelta(days=15),
)
event.create_all_recurrences()

View File

@ -443,7 +443,7 @@ def test_bookings_api_filter_event(app, user):
recurring_event = Event.objects.create(
slug='recurring-event',
start_datetime=now(),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=2,
waiting_list_places=1,
agenda=agenda,

View File

@ -237,12 +237,12 @@ def test_event_notify_checked(app, user):
'days_in, days_out, err_msg',
[
(1, None, 'Expected a list of items but got type "int".'),
('2', [2], None),
([3], [3], None),
(['4'], [4], None),
([1, 2], [1, 2], None),
(['2', '3'], [2, 3], None),
('4, 5', [4, 5], None),
('2', [3], None),
([3], [4], None),
(['4'], [5], None),
([1, 2], [2, 3], None),
(['2', '3'], [3, 4], None),
('4, 5', [5, 6], None),
],
)
def test_string_or_list_serialiser(app, user, days_in, days_out, err_msg):
@ -444,7 +444,7 @@ def test_add_event(app, user):
)
event = Event.objects.filter(agenda=agenda).get(slug='foo-bar-event-2')
assert event.description == 'A recurrent event'
assert event.recurrence_days == [3]
assert event.recurrence_days == [4]
assert event.recurrence_week_interval == 2
assert event.recurrence_end_date is None
# some occurrences created
@ -472,7 +472,7 @@ def test_add_event(app, user):
event = Event.objects.filter(agenda=agenda).get(slug='foo-bar-event-3')
assert Event.objects.filter(agenda=agenda).count() == 39
assert event.description == 'A recurrent event having recurrences'
assert event.recurrence_days == [0, 3, 5]
assert event.recurrence_days == [1, 4, 6]
assert event.recurrence_week_interval == 2
assert event.recurrence_end_date == datetime.date(2021, 12, 27)
assert event.custom_fields == {
@ -869,7 +869,7 @@ def test_delete_recurring_event_forbidden(app, user):
start_datetime=start_datetime,
places=10,
agenda=agenda,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=7),
)
event.create_all_recurrences()
@ -910,7 +910,7 @@ def test_events(app, user):
slug='recurring-event-slug',
label='Recurring Event Label',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=8),
places=10,
agenda=agenda,
@ -1339,7 +1339,7 @@ def test_events_check_status_events(app, user):
slug='recurring-event-slug',
label='Recurring Event Label',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=7),
places=10,
agenda=agenda,
@ -1814,7 +1814,7 @@ def test_events_check_lock_events(app, user):
slug='recurring-event-slug',
label='Recurring Event Label',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=7),
places=10,
agenda=agenda,
@ -2090,7 +2090,7 @@ def test_events_invoiced_events(app, user):
slug='recurring-event-slug',
label='Recurring Event Label',
start_datetime=start_datetime,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=7),
places=10,
agenda=agenda,

View File

@ -1229,7 +1229,7 @@ def test_agenda_events_day_view(app, admin_user):
start_datetime=recurring_start_datetime,
places=10,
agenda=agenda,
recurrence_days=[recurring_start_datetime.weekday()],
recurrence_days=[recurring_start_datetime.isoweekday()],
recurrence_end_date=recurring_start_datetime + datetime.timedelta(days=15),
)
event.create_all_recurrences()
@ -1252,7 +1252,7 @@ def test_agenda_events_day_view(app, admin_user):
start_datetime=start_datetime,
places=10,
agenda=agenda,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=15),
)
event.create_all_recurrences()
@ -1302,7 +1302,7 @@ def test_agenda_events_week_view(app, admin_user):
start_datetime=start_datetime,
places=10,
agenda=agenda,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=60),
)
event.create_all_recurrences()
@ -1333,7 +1333,7 @@ def test_agenda_events_week_view(app, admin_user):
start_datetime=start_datetime,
places=10,
agenda=agenda,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=60),
)
event.create_all_recurrences()
@ -1396,7 +1396,7 @@ def test_agenda_events_month_view(app, admin_user):
start_datetime=start_datetime,
places=10,
agenda=agenda,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=60),
)
event.create_all_recurrences()
@ -1434,7 +1434,7 @@ def test_agenda_events_month_view(app, admin_user):
start_datetime=start_datetime,
places=10,
agenda=agenda,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=60),
)
event.create_all_recurrences()
@ -1528,6 +1528,7 @@ def test_agenda_open_events_view(app, admin_user, manager_user):
start_datetime=start_datetime,
places=10,
agenda=agenda,
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=30),
)
event.create_all_recurrences()

View File

@ -79,7 +79,7 @@ def test_add_recurring_event(app, admin_user):
resp.form['start_datetime_1'] = '17:00'
resp.form['places'] = 10
resp.form['frequency'] = 'unique' # not a recurring event
resp.form['recurrence_days'] = [1]
resp.form['recurrence_days'] = [2]
resp.form.submit().follow()
event = Event.objects.get()
@ -91,7 +91,7 @@ def test_add_recurring_event(app, admin_user):
resp.form.submit().follow()
event = Event.objects.get(primary_event__isnull=True)
assert event.recurrence_days == [1]
assert event.recurrence_days == [2]
assert Event.objects.filter(primary_event=event).count() == 49
event.delete()
@ -100,7 +100,7 @@ def test_add_recurring_event(app, admin_user):
resp.form.submit().follow()
event = Event.objects.get(primary_event__isnull=True)
assert event.recurrence_days == [1]
assert event.recurrence_days == [2]
assert Event.objects.filter(primary_event=event).count() == 5
# add recurring event with end date in a very long time
@ -374,7 +374,7 @@ def test_edit_recurring_event(settings, app, admin_user, freezer):
app = login(app)
resp = app.get('/manage/agendas/%s/events/%s/edit' % (agenda.id, event.id))
resp.form['frequency'] = 'recurring'
resp.form['recurrence_days'] = [localtime().weekday()]
resp.form['recurrence_days'] = [localtime().isoweekday()]
resp = resp.form.submit()
# no end date, events are created for the year to come
@ -425,7 +425,7 @@ def test_edit_recurring_event(settings, app, admin_user, freezer):
assert not Event.objects.filter(primary_event=event).exists()
# same goes with changing slug
event.recurrence_days = [1]
event.recurrence_days = [2]
event.save()
event.create_all_recurrences()
event_recurrence = Event.objects.get(primary_event=event, start_datetime=event.start_datetime)
@ -483,7 +483,7 @@ def test_edit_recurring_event_with_end_date(settings, app, admin_user, freezer):
freezer.move_to('2021-01-12 12:10')
agenda = Agenda.objects.create(label='Foo bar', kind='events')
event = Event.objects.create(
start_datetime=now(), places=10, recurrence_days=list(range(7)), agenda=agenda
start_datetime=now(), places=10, recurrence_days=list(range(1, 8)), agenda=agenda
)
app = login(app)
@ -676,7 +676,7 @@ def test_delete_recurring_event(app, admin_user, freezer):
start_datetime=start_datetime,
places=10,
agenda=agenda,
recurrence_days=[start_datetime.weekday()],
recurrence_days=[start_datetime.isoweekday()],
recurrence_end_date=start_datetime + datetime.timedelta(days=15),
)
event.create_all_recurrences()
@ -3336,7 +3336,7 @@ def test_duplicate_event_creates_recurrences(app, admin_user):
recurring_event = Event.objects.create(
agenda=agenda,
start_datetime=event_start,
recurrence_days=[0, 1, 2, 3, 4, 5, 6],
recurrence_days=[1, 2, 3, 4, 5, 6, 7],
recurrence_end_date=event_start + datetime.timedelta(days=6),
places=10,
label='Foo',

View File

@ -111,7 +111,7 @@ def test_events_timesheet_slots(app, admin_user):
start_datetime=start,
places=10,
agenda=agenda,
recurrence_days=[0, 1],
recurrence_days=[1, 2],
recurrence_end_date=end,
)
recurring_event1.create_all_recurrences()
@ -120,7 +120,7 @@ def test_events_timesheet_slots(app, admin_user):
start_datetime=start,
places=10,
agenda=agenda,
recurrence_days=[1, 2],
recurrence_days=[2, 3],
recurrence_end_date=end,
)
recurring_event2.create_all_recurrences()
@ -457,7 +457,7 @@ def test_events_timesheet_booked(app, admin_user):
start_datetime=event_date,
places=10,
agenda=agenda,
recurrence_days=[1],
recurrence_days=[2],
recurrence_end_date=event_date + datetime.timedelta(days=1),
)
recurring_event1.create_all_recurrences()
@ -467,7 +467,7 @@ def test_events_timesheet_booked(app, admin_user):
start_datetime=event_date,
places=10,
agenda=agenda,
recurrence_days=[1],
recurrence_days=[2],
recurrence_end_date=event_date + datetime.timedelta(days=1),
)
recurring_event2.create_all_recurrences()
@ -791,7 +791,7 @@ def test_events_timesheet_date_display(app, admin_user):
start_datetime=make_aware(datetime.datetime(2022, 1, 1, 12, 0)),
places=10,
agenda=agenda,
recurrence_days=[0],
recurrence_days=[1],
recurrence_end_date=datetime.date(2022, 4, 1),
)
recurring_event.create_all_recurrences()
@ -1002,7 +1002,7 @@ def test_events_timesheet_csv(app, admin_user):
start_datetime=make_aware(datetime.datetime(2022, 2, 1, 12, 0)),
places=10,
agenda=agenda,
recurrence_days=[0],
recurrence_days=[1],
recurrence_end_date=datetime.date(2022, 4, 1),
)
recurring_event.create_all_recurrences()
@ -1140,7 +1140,7 @@ def test_event_timesheet_wrong_event(app, admin_user):
app = login(app)
app.get('/manage/agendas/%s/events/%s/timesheet' % (agenda.pk, event.pk), status=404)
event.cancelled = False
event.recurrence_days = [1]
event.recurrence_days = [2]
event.save()
app.get('/manage/agendas/%s/events/%s/timesheet' % (agenda.pk, event.pk), status=404)

View File

@ -1349,7 +1349,7 @@ def test_recurring_events_manage_exceptions(settings, app, admin_user, freezer):
resp = app.get('/manage/agendas/%s/settings' % agenda.id)
assert 'Recurrence exceptions' not in resp.text
event.recurrence_days = list(range(7))
event.recurrence_days = list(range(1, 8))
event.recurrence_end_date = now() + datetime.timedelta(days=31)
event.save()
event.create_all_recurrences()
@ -1390,7 +1390,7 @@ def test_recurring_events_exceptions_report(settings, app, admin_user, freezer):
event = Event.objects.create(
start_datetime=now(),
places=10,
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
recurrence_end_date=now() + datetime.timedelta(days=30),
agenda=agenda,
)

View File

@ -43,7 +43,7 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
resp = resp.click('Add custody rule')
resp.form['guardian'] = father.pk
resp.form['days'] = list(range(7))
resp.form['days'] = list(range(1, 8))
resp.form['weeks'] = 'even'
resp = resp.form.submit()
assert resp.location.endswith('/manage/shared-custody/%s/settings/' % agenda.pk)
@ -53,7 +53,7 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
resp = resp.click('Add custody rule')
resp.form['guardian'] = mother.pk
resp.form['days'] = list(range(7))
resp.form['days'] = list(range(1, 8))
resp.form['weeks'] = 'odd'
resp = resp.form.submit().follow()
assert 'Custody rules are not complete.' not in resp.text
@ -61,14 +61,14 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
assert 'Jane Doe, daily, on odd weeks' in resp.text
resp = resp.click('John Doe, daily, on even weeks')
resp.form['days'] = list(range(6))
resp.form['days'] = list(range(1, 7))
resp = resp.form.submit()
assert resp.location.endswith('/manage/shared-custody/%s/settings/' % agenda.pk)
resp = resp.follow()
assert 'Custody rules are not complete.' in resp.text
resp = resp.click('John Doe, from Monday to Saturday, on even weeks')
resp.form['days'] = [0]
resp.form['days'] = [1]
resp.form['weeks'] = 'odd'
resp = resp.form.submit()
assert 'Rule overlaps existing rules.' in resp.text
@ -100,7 +100,7 @@ def test_shared_custody_agenda_settings_rules_require_days(app, admin_user):
resp = resp.form.submit()
assert 'This field is required.' in resp.text
resp.form['days'] = [0]
resp.form['days'] = [1]
resp.form.submit().follow()
assert SharedCustodyRule.objects.count() == 1
@ -163,7 +163,7 @@ def test_shared_custody_agenda_month_view(app, admin_user):
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, child=child, date_start=datetime.date(2022, 1, 1)
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)), weeks='even')
app = login(app)
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
@ -171,7 +171,7 @@ def test_shared_custody_agenda_month_view(app, admin_user):
assert 'February 2022' in resp.text
assert 'Configuration is not completed yet.' in resp.text
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='odd')
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
assert 'Configuration is not completed yet.' not in resp.text
@ -223,7 +223,7 @@ def test_shared_custody_agenda_month_view_dates(app, admin_user):
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, child=child, date_start=datetime.date(2022, 1, 1)
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)))
app = login(app)
@ -278,10 +278,10 @@ def test_shared_custody_agenda_month_view_queries(app, admin_user):
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[0, 1, 2], weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[3, 4, 5, 6], weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[0, 1, 2], weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[3, 4, 5, 6], weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[1, 2, 3], weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[4, 5, 6, 7], weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[1, 2, 3], weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[4, 5, 6, 7], weeks='even')
for i in range(1, 10):
SharedCustodyPeriod.objects.create(
@ -397,8 +397,8 @@ def test_shared_custody_agenda_holiday_rules(app, admin_user):
assert [x[2] for x in resp.form['holiday'].options] == ['---------', 'Vacances de Noël']
# holiday name is shown on month view
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)), weeks='odd')
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)), weeks='even')
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(1, 8)), weeks='odd')
resp = app.get('/manage/shared-custody/%s/2022/12/' % agenda.pk)
assert 'John Doe (Vacances de Noël)' in resp.text

View File

@ -1681,7 +1681,7 @@ def test_agenda_events_recurrence_duplicate(freezer):
event = Event.objects.create(
agenda=orig_agenda,
start_datetime=now_,
recurrence_days=[now_.weekday()],
recurrence_days=[now_.isoweekday()],
label='Event',
places=10,
recurrence_end_date=end,
@ -2375,7 +2375,7 @@ def test_recurring_events(freezer):
event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=[now().weekday()],
recurrence_days=[now().isoweekday()],
label='Event',
places=10,
waiting_list_places=10,
@ -2419,7 +2419,7 @@ def test_recurring_events_dst(freezer, settings):
settings.TIME_ZONE = 'Europe/Brussels'
agenda = Agenda.objects.create(label='Agenda', kind='events')
event = Event.objects.create(
agenda=agenda, start_datetime=now(), recurrence_days=[now().weekday()], places=5
agenda=agenda, start_datetime=now(), recurrence_days=[now().isoweekday()], places=5
)
event.refresh_from_db()
dt = localtime()
@ -2444,7 +2444,7 @@ def test_recurring_events_repetition(freezer):
event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=list(range(7)), # everyday
recurrence_days=list(range(1, 8)), # everyday
places=5,
)
event.refresh_from_db()
@ -2460,7 +2460,7 @@ def test_recurring_events_repetition(freezer):
for i in range(len(recurrences) - 1):
assert recurrences[i].start_datetime + datetime.timedelta(days=1) == recurrences[i + 1].start_datetime
event.recurrence_days = list(range(5)) # from Monday to Friday
event.recurrence_days = list(range(1, 6)) # from Monday to Friday
event.save()
recurrences = event.get_recurrences(
localtime() + datetime.timedelta(days=1), localtime() + datetime.timedelta(days=7)
@ -2470,7 +2470,7 @@ def test_recurring_events_repetition(freezer):
assert recurrences[1].start_datetime == start_datetime + datetime.timedelta(days=5)
assert recurrences[-1].start_datetime == start_datetime + datetime.timedelta(days=7)
event.recurrence_days = [localtime(event.start_datetime).weekday()] # from Monday to Friday
event.recurrence_days = [localtime(event.start_datetime).isoweekday()]
event.recurrence_week_interval = 2
event.save()
recurrences = event.get_recurrences(
@ -2484,7 +2484,7 @@ def test_recurring_events_repetition(freezer):
recurrences[i].start_datetime + datetime.timedelta(days=14) == recurrences[i + 1].start_datetime
)
event.recurrence_days = [3] # Tuesday but start_datetime is a Wednesday
event.recurrence_days = [4] # Tuesday but start_datetime is a Wednesday
event.recurrence_week_interval = 1
event.save()
recurrences = event.get_recurrences(localtime(), localtime() + datetime.timedelta(days=10))
@ -2499,7 +2499,7 @@ def test_recurring_events_with_end_date():
event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=5,
recurrence_end_date=(now() + datetime.timedelta(days=5)).date(),
)
@ -2528,7 +2528,7 @@ def test_recurring_events_exceptions(freezer):
event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=5,
)
@ -2593,21 +2593,21 @@ def test_recurring_events_exceptions_update_recurrences(freezer):
daily_event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=5,
recurrence_end_date=datetime.date(year=2021, month=5, day=8),
)
weekly_event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=[now().weekday()],
recurrence_days=[now().isoweekday()],
places=5,
recurrence_end_date=datetime.date(year=2021, month=6, day=1),
)
weekly_event_no_end_date = Event.objects.create(
agenda=agenda,
start_datetime=now() + datetime.timedelta(hours=2),
recurrence_days=[now().weekday()],
recurrence_days=[now().isoweekday()],
places=5,
)
Event.create_events_recurrences([daily_event, weekly_event, weekly_event_no_end_date])
@ -2657,7 +2657,7 @@ def test_recurring_events_exceptions_update_recurrences_start_datetime_modified(
daily_event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=5,
recurrence_end_date=datetime.date(year=2021, month=9, day=13),
)
@ -2702,7 +2702,7 @@ def test_recurring_events_update_recurrences_new_event(freezer):
daily_event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=5,
recurrence_end_date=now() + datetime.timedelta(days=7),
)
@ -2713,7 +2713,7 @@ def test_recurring_events_update_recurrences_new_event(freezer):
daily_event_no_end_date = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=[1],
recurrence_days=[2],
recurrence_week_interval=3,
places=5,
)
@ -2723,7 +2723,7 @@ def test_recurring_events_update_recurrences_new_event(freezer):
daily_event = Event.objects.create(
agenda=agenda,
start_datetime=now().replace(hour=10),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=5,
recurrence_end_date=now() + datetime.timedelta(days=7),
)
@ -2738,7 +2738,7 @@ def test_recurring_events_display(freezer):
event = Event.objects.create(
agenda=agenda,
start_datetime=now() + datetime.timedelta(days=1),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=5,
)
@ -2747,19 +2747,19 @@ def test_recurring_events_display(freezer):
freezer.move_to('2021-01-07 12:30')
assert event.get_recurrence_display() == 'Daily at 1:30 p.m.'
event.recurrence_days = [1, 2, 3, 4]
event.recurrence_days = [2, 3, 4, 5]
event.save()
assert event.get_recurrence_display() == 'From Tuesday to Friday at 1:30 p.m.'
event.recurrence_days = [4, 5, 6]
event.recurrence_days = [5, 6, 7]
event.save()
assert event.get_recurrence_display() == 'From Friday to Sunday at 1:30 p.m.'
event.recurrence_days = [1, 4, 6]
event.recurrence_days = [2, 5, 7]
event.save()
assert event.get_recurrence_display() == 'On Tuesdays, Fridays, Sundays at 1:30 p.m.'
event.recurrence_days = [0]
event.recurrence_days = [1]
event.recurrence_week_interval = 2
event.save()
assert event.get_recurrence_display() == 'On Mondays at 1:30 p.m., once every two weeks'
@ -2967,7 +2967,7 @@ def test_recurring_events_create_past_recurrences(freezer):
daily_event = Event.objects.create(
agenda=agenda,
start_datetime=now() - datetime.timedelta(days=3),
recurrence_days=list(range(7)),
recurrence_days=list(range(1, 8)),
places=5,
recurrence_end_date=now() + datetime.timedelta(days=3),
)
@ -2984,8 +2984,8 @@ def test_shared_custody_agenda():
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='even', guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='odd', guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(1, 8)), weeks='even', guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(1, 8)), weeks='odd', guardian=mother)
slots = agenda.get_custody_slots(now().date(), now().date() + datetime.timedelta(days=30))
assert [x.date for x in slots] == [now().date() + datetime.timedelta(days=i) for i in range(30)]
@ -3043,8 +3043,8 @@ def test_shared_custody_agenda_different_periodicity():
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, days=[1, 2, 3], guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=[0, 4, 5, 6], guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, days=[2, 3, 4], guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=[1, 5, 6, 7], guardian=mother)
slots = agenda.get_custody_slots(now().date(), now().date() + datetime.timedelta(days=14))
assert [(x.date.strftime('%A %d/%m'), str(x.guardian)) for x in slots] == [
('Tuesday 22/02', 'John Doe'),
@ -3257,22 +3257,22 @@ def test_shared_custody_agenda_rule_label():
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(1, 8)))
assert rule.label == 'daily'
rule.days = [1, 2, 3, 4]
rule.days = [2, 3, 4, 5]
rule.save()
assert rule.label == 'from Tuesday to Friday'
rule.days = [4, 5, 6]
rule.days = [5, 6, 7]
rule.save()
assert rule.label == 'from Friday to Sunday'
rule.days = [1, 4, 6]
rule.days = [2, 5, 7]
rule.save()
assert rule.label == 'on Tuesdays, Fridays, Sundays'
rule.days = [0]
rule.days = [1]
rule.weeks = 'even'
rule.save()
assert rule.label == 'on Mondays, on even weeks'
@ -3535,8 +3535,8 @@ def test_shared_custody_agenda_holiday_rules_application():
group=christmas_holiday,
)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='even', guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='odd', guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(1, 8)), weeks='even', guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(1, 8)), weeks='odd', guardian=mother)
rule = SharedCustodyHolidayRule.objects.create(agenda=agenda, guardian=father, holiday=christmas_holiday)
rule.update_or_create_periods()
@ -3585,8 +3585,8 @@ def test_shared_custody_agenda_update_holiday_rules_command():
group=christmas_holiday,
)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='even', guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='odd', guardian=mother)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(1, 8)), weeks='even', guardian=father)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(1, 8)), weeks='odd', guardian=mother)
rule = SharedCustodyHolidayRule.objects.create(agenda=agenda, guardian=father, holiday=christmas_holiday)
rule.update_or_create_periods()

View File

@ -265,7 +265,7 @@ def test_import_export_recurring_event(app, freezer):
event = Event.objects.create(
agenda=agenda,
start_datetime=now(),
recurrence_days=[now().weekday()],
recurrence_days=[now().isoweekday()],
recurrence_week_interval=2,
places=10,
slug='test',
@ -284,7 +284,7 @@ def test_import_export_recurring_event(app, freezer):
assert Agenda.objects.count() == 1
assert Event.objects.count() == 28
event = Agenda.objects.get(label='Foo Bar').event_set.filter(primary_event__isnull=True).get()
assert event.recurrence_days == [now().weekday()]
assert event.recurrence_days == [now().isoweekday()]
assert event.recurrence_week_interval == 2
# importing event with end recurrence date removes recurrences