Garde alternée, faire que un enfant = un agenda (#71632) #12

Manually merged
vdeniaud merged 1 commits from wip/71632-Garde-alternee-faire-que-un-enfa into main 2022-11-29 10:12:44 +01:00
14 changed files with 194 additions and 205 deletions

View File

@ -0,0 +1,25 @@
# Generated by Django 2.2.26 on 2022-11-28 13:41
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agendas', '0140_add_timeperiod_date_field'),
]
operations = [
migrations.AddField(
model_name='sharedcustodyagenda',
name='child',
field=models.ForeignKey(
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name='+',
to='agendas.Person',
verbose_name='Child',
),
),
]

View File

@ -0,0 +1,24 @@
# Generated by Django 2.2.26 on 2022-11-28 13:41
from django.db import migrations
def populate_child_column(apps, schema_editor):
SharedCustodyAgenda = apps.get_model('agendas', 'SharedCustodyAgenda')
for agenda in SharedCustodyAgenda.objects.all():
child = agenda.children.first()
if child:
agenda.child = child
agenda.save()
else:
agenda.delete()
Review

migration très naïve, c'est voulu parce que peu de legacy ?

migration très naïve, c'est voulu parce que peu de legacy ?
Review

Yup, zéro legacy à part un ou deux tests de Stéphane, le but c'est juste que l'ajout du champ null=False passe.

Yup, zéro legacy à part un ou deux tests de Stéphane, le but c'est juste que l'ajout du champ null=False passe.
class Migration(migrations.Migration):
dependencies = [
('agendas', '0141_shared_custody_add_child_field'),
]
operations = [migrations.RunPython(populate_child_column, migrations.RunPython.noop)]

View File

@ -0,0 +1,28 @@
# Generated by Django 2.2.26 on 2022-11-28 13:48
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('agendas', '0142_shared_custody_populate_child_field'),
]
operations = [
migrations.RemoveField(
model_name='sharedcustodyagenda',
name='children',
),
migrations.AlterField(
model_name='sharedcustodyagenda',
name='child',
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name='+',
to='agendas.Person',
verbose_name='Child',
),
),
]

View File

@ -845,7 +845,7 @@ class Agenda(models.Model):
@staticmethod
def filter_for_guardian(qs, guardian_external_id, child_external_id, min_start=None, max_start=None):
agendas = SharedCustodyAgenda.objects.filter(children__user_external_id=child_external_id).order_by(
agendas = SharedCustodyAgenda.objects.filter(child__user_external_id=child_external_id).order_by(
'-date_start'
)
if max_start:
@ -3221,14 +3221,15 @@ class SharedCustodyAgenda(models.Model):
second_guardian = models.ForeignKey(
Person, verbose_name=_('Second guardian'), on_delete=models.CASCADE, related_name='+'
)
children = models.ManyToManyField(Person, related_name='agendas')
child = models.ForeignKey(Person, verbose_name=_('Child'), on_delete=models.CASCADE, related_name='+')
date_start = models.DateField(_('Start'))
@property
def label(self):
return _('Custody agenda of %(first_guardian)s and %(second_guardian)s') % {
return _('Custody agenda of %(first_guardian)s and %(second_guardian)s for %(child)s') % {
'first_guardian': self.first_guardian,
'second_guardian': self.second_guardian,
'child': self.child,
}
def get_absolute_url(self):

View File

@ -585,13 +585,6 @@ class SubscriptionSerializer(serializers.ModelSerializer):
return attrs
class PersonSerializer(serializers.ModelSerializer):
class Meta:
model = Person
fields = ['user_external_id', 'first_name', 'last_name']
extra_kwargs = {'user_external_id': {'validators': []}}
class SharedCustodyAgendaCreateSerializer(serializers.Serializer):
period_mirrors = {
'even': 'odd',
@ -608,7 +601,9 @@ class SharedCustodyAgendaCreateSerializer(serializers.Serializer):
other_guardian_first_name = serializers.CharField(max_length=250)
other_guardian_last_name = serializers.CharField(max_length=250)
other_guardian_id = serializers.CharField(max_length=250)
children = PersonSerializer(many=True)
child_first_name = serializers.CharField(max_length=250)
child_last_name = serializers.CharField(max_length=250)
child_id = serializers.CharField(max_length=250)
weeks = serializers.ChoiceField(required=False, choices=['', 'even', 'odd'])
date_start = serializers.DateField(required=True)
@ -667,21 +662,20 @@ class SharedCustodyAgendaCreateSerializer(serializers.Serializer):
'last_name': validated_data['other_guardian_last_name'],
},
)
self.agenda = SharedCustodyAgenda.objects.create(
first_guardian=guardian, second_guardian=other_guardian, date_start=validated_data['date_start']
child, dummy = Person.objects.get_or_create(
user_external_id=validated_data['child_id'],
defaults={
'first_name': validated_data['child_first_name'],
'last_name': validated_data['child_last_name'],
},
)
children = []
children_data = validated_data.pop('children')
for child in children_data:
children.append(
Person.objects.get_or_create(
user_external_id=child['user_external_id'],
defaults={'first_name': child['first_name'], 'last_name': child['last_name']},
)[0]
)
self.agenda.children.set(children)
self.agenda = SharedCustodyAgenda.objects.create(
first_guardian=guardian,
second_guardian=other_guardian,
child=child,
date_start=validated_data['date_start'],
)
if validated_data.get('weeks'):
self.create_custody_rules(guardian, validated_data['weeks'], create_mirror_for=other_guardian)

View File

@ -130,11 +130,6 @@ urlpatterns = [
views.shared_custody_agenda,
name='api-shared-custody-agenda',
),
path(
'shared-custody/<int:agenda_pk>/add-child/',
views.shared_custody_agenda_add_child,
name='api-shared-custody-agenda-add-child',
),
path('statistics/', views.statistics_list, name='api-statistics-list'),
path('statistics/bookings/', views.bookings_statistics, name='api-statistics-bookings'),
]

View File

@ -51,7 +51,6 @@ from chrono.agendas.models import (
Desk,
Event,
MeetingType,
Person,
SharedCustodyAgenda,
Subscription,
TimePeriodException,
@ -3023,34 +3022,6 @@ class SharedCustodyAgendaAPI(APIView):
shared_custody_agenda = SharedCustodyAgendaAPI.as_view()
class SharedCustodyAgendaAddChild(APIView):
permission_classes = (permissions.IsAuthenticated,)
serializer_class = serializers.PersonSerializer
def post(self, request, agenda_pk):
agenda = get_object_or_404(SharedCustodyAgenda, pk=agenda_pk)
serializer = self.serializer_class(data=request.data)
if not serializer.is_valid():
raise APIErrorBadRequest(N_('invalid payload'), errors=serializer.errors)
data = serializer.validated_data
with transaction.atomic():
child, dummy = Person.objects.get_or_create(
user_external_id=data['user_external_id'],
defaults={'first_name': data['first_name'], 'last_name': data['last_name']},
)
if child.agendas.exists():
raise APIError(N_('This child already has one custody agenda.'))
agenda.children.add(child)
return Response({'err': 0, 'data': {'child_id': child.pk}})
shared_custody_agenda_add_child = SharedCustodyAgendaAddChild.as_view()
class StatisticsList(APIView):
permission_classes = (permissions.IsAuthenticated,)

View File

@ -420,9 +420,11 @@ def test_datetimes_multiple_agendas_queries(app):
child = Person.objects.create(user_external_id='xxx', first_name='James', last_name='Doe')
for i in range(5):
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now() - datetime.timedelta(days=5 + i)
first_guardian=father,
second_guardian=mother,
child=child,
date_start=now() - datetime.timedelta(days=5 + i),
)
agenda.children.add(child)
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')
@ -732,9 +734,8 @@ def test_datetimes_multiple_agendas_shared_custody(app):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
father_rule = SharedCustodyRule.objects.create(
agenda=agenda, guardian=father, days=list(range(7)), weeks='even'
@ -873,9 +874,8 @@ def test_datetimes_multiple_agendas_shared_custody_other_rules(app):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
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])
@ -964,9 +964,8 @@ def test_datetimes_multiple_agendas_shared_custody_recurring_event(app):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
father_rule = SharedCustodyRule.objects.create(
agenda=agenda, guardian=father, days=list(range(7)), weeks='even'
@ -1169,9 +1168,8 @@ def test_datetimes_multiple_agendas_shared_custody_holiday_rules(app):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
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)
@ -1261,9 +1259,8 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
resp = app.get(
@ -1284,9 +1281,11 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
assert len(resp.json['data']) == 0
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=datetime.date(year=2022, month=3, day=10)
first_guardian=father,
second_guardian=mother,
child=child,
date_start=datetime.date(year=2022, month=3, day=10),
)
agenda.children.add(child)
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=list(range(7)))
resp = app.get(
@ -1308,9 +1307,11 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
]
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=datetime.date(year=2022, month=3, day=17)
first_guardian=father,
second_guardian=mother,
child=child,
date_start=datetime.date(year=2022, month=3, day=17),
)
agenda.children.add(child)
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')
@ -1351,9 +1352,9 @@ def test_datetimes_multiple_agendas_shared_custody_date_start(app):
agenda = SharedCustodyAgenda.objects.create(
first_guardian=other_person,
second_guardian=mother,
child=child,
date_start=datetime.date(year=2022, month=3, day=22),
)
agenda.children.add(child)
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')

View File

@ -146,9 +146,8 @@ def test_recurring_events_api_list_shared_custody(app):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
custody_agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
custody_agenda.children.add(child)
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')
@ -278,16 +277,17 @@ def test_recurring_events_api_list_shared_custody_start_date(app):
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
custody_agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
custody_agenda.children.add(child)
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')
custody_agenda2 = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now() + datetime.timedelta(days=15)
first_guardian=father,
second_guardian=mother,
child=child,
date_start=now() + datetime.timedelta(days=15),
)
custody_agenda2.children.add(child)
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')
@ -384,9 +384,8 @@ def test_recurring_events_api_list_multiple_agendas_queries(app):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='xxx', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
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')

View File

@ -603,9 +603,8 @@ def test_api_events_fillslots_multiple_agendas_shared_custody(app, user):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=[0, 1, 2])
SharedCustodyRule.objects.create(agenda=agenda, guardian=mother, days=[3, 4, 5, 6])
@ -678,15 +677,16 @@ def test_api_events_fillslots_multiple_agendas_shared_custody_date_start(app, us
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
agenda2 = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=datetime.date(year=2022, month=3, day=10)
first_guardian=father,
second_guardian=mother,
child=child,
date_start=datetime.date(year=2022, month=3, day=10),
)
agenda2.children.add(child)
SharedCustodyRule.objects.create(agenda=agenda2, guardian=mother, days=list(range(7)))
app.authorization = ('Basic', ('john.doe', 'password'))

View File

@ -1298,9 +1298,8 @@ def test_recurring_events_api_fillslots_multiple_agendas_queries(app, user):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='xxx', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
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')
@ -1334,9 +1333,8 @@ def test_recurring_events_api_fillslots_shared_custody(app, user, freezer):
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
agenda.children.add(child)
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])
@ -1379,9 +1377,11 @@ def test_recurring_events_api_fillslots_shared_custody(app, user, freezer):
# give father full custody from 14/03/2022
agenda2 = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=datetime.date(year=2022, month=3, day=14)
first_guardian=father,
second_guardian=mother,
child=child,
date_start=datetime.date(year=2022, month=3, day=14),
)
agenda2.children.add(child)
SharedCustodyRule.objects.create(agenda=agenda2, guardian=father, days=list(range(7)))
Booking.objects.all().delete()

View File

@ -23,31 +23,21 @@ def test_add_shared_custody_agenda(app, user, settings):
'other_guardian_first_name': 'Jane',
'other_guardian_last_name': 'Doe',
'other_guardian_id': 'yyy',
'children': [
{
'first_name': 'James',
'last_name': 'Doe',
'user_external_id': 'zzz',
},
{
'first_name': 'Arthur',
'last_name': 'Doe',
'user_external_id': '123',
},
],
'child_first_name': 'James',
'child_last_name': 'Doe',
'child_id': 'zzz',
'date_start': '2020-10-20',
}
resp = app.post_json('/api/shared-custody/', params=params)
first_guardian = Person.objects.get(user_external_id='xxx', first_name='John', last_name='Doe')
second_guardian = Person.objects.get(user_external_id='yyy', first_name='Jane', last_name='Doe')
first_chidren = Person.objects.get(user_external_id='zzz', first_name='James', last_name='Doe')
second_children = Person.objects.get(user_external_id='123', first_name='Arthur', last_name='Doe')
child = Person.objects.get(user_external_id='zzz', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.get()
assert agenda.first_guardian == first_guardian
assert agenda.second_guardian == second_guardian
assert set(agenda.children.all()) == {first_chidren, second_children}
assert agenda.child == child
assert resp.json['data'] == {
'id': agenda.pk,
@ -62,13 +52,9 @@ def test_add_shared_custody_agenda(app, user, settings):
'other_guardian_first_name': 'Other',
'other_guardian_last_name': 'Doe',
'other_guardian_id': 'other',
'children': [
{
'first_name': 'Bruce',
'last_name': 'Doe',
'user_external_id': 'bruce',
},
],
'child_first_name': 'Bruce',
'child_last_name': 'Doe',
'child_id': 'bruce',
'date_start': '2020-10-20',
}
resp = app.post_json('/api/shared-custody/', params=params)
@ -94,13 +80,9 @@ def test_add_shared_custody_agenda_with_rules(app, user, settings):
'other_guardian_first_name': 'Jane',
'other_guardian_last_name': 'Doe',
'other_guardian_id': 'yyy',
'children': [
{
'first_name': 'James',
'last_name': 'Doe',
'user_external_id': 'zzz',
},
],
'child_first_name': 'James',
'child_last_name': 'Doe',
'child_id': 'zzz',
'date_start': '2020-10-20',
}
@ -197,66 +179,12 @@ def test_add_shared_custody_agenda_with_rules(app, user, settings):
assert resp.json['errors']['non_field_errors'][0] == 'Short holidays cannot be cut into quarters.'
def test_shared_custody_agenda_add_child(app, user, settings):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
)
app.authorization = ('Basic', ('john.doe', 'password'))
params = {
'first_name': 'James',
'last_name': 'Doe',
'user_external_id': 'xxx',
}
resp = app.post_json('/api/shared-custody/%s/add-child/' % agenda.pk, params=params)
child = Person.objects.get(first_name='James', last_name='Doe', user_external_id='xxx')
assert resp.json['data']['child_id'] == child.pk
assert agenda.children.count() == 1
assert Person.objects.count() == 3
# adding again throws error
resp = app.post_json('/api/shared-custody/%s/add-child/' % agenda.pk, params=params)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'This child already has one custody agenda.'
assert agenda.children.count() == 1
assert Person.objects.count() == 3
params = {
'first_name': 'Jack',
'last_name': 'Doe',
'user_external_id': 'yyy',
}
resp = app.post_json('/api/shared-custody/%s/add-child/' % agenda.pk, params=params)
child = Person.objects.get(first_name='Jack', last_name='Doe', user_external_id='yyy')
assert resp.json['data']['child_id'] == child.pk
assert agenda.children.count() == 2
assert Person.objects.count() == 4
other_father = Person.objects.create(
user_external_id='other_father_id', first_name='John', last_name='Doe'
)
other_mother = Person.objects.create(
user_external_id='other_mother_id', first_name='Jane', last_name='Doe'
)
other_agenda = SharedCustodyAgenda.objects.create(
first_guardian=other_father, second_guardian=other_mother, date_start=now()
)
resp = app.post_json('/api/shared-custody/%s/add-child/' % other_agenda.pk, params=params)
assert resp.json['err'] == 1
assert resp.json['err_desc'] == 'This child already has one custody agenda.'
def test_shared_custody_agenda_update_date_start(app, user, settings):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
app.authorization = ('Basic', ('john.doe', 'password'))

View File

@ -29,8 +29,9 @@ with open('tests/data/holidays.ics') as f:
def test_shared_custody_agenda_settings_rules(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
app = login(app)
@ -85,8 +86,9 @@ def test_shared_custody_agenda_settings_rules(app, admin_user):
def test_shared_custody_agenda_settings_rules_require_days(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
app = login(app)
@ -107,8 +109,9 @@ def test_shared_custody_agenda_settings_rules_require_days(app, admin_user):
def test_shared_custody_agenda_settings_periods(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
app = login(app)
@ -156,14 +159,15 @@ def test_shared_custody_agenda_settings_periods(app, admin_user):
def test_shared_custody_agenda_month_view(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=datetime.date(2022, 1, 1)
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')
app = login(app)
resp = app.get('/manage/shared-custody/%s/' % agenda.pk).follow()
assert 'Custody agenda of John Doe and Jane Doe' in resp.text
assert 'Custody agenda of John Doe and Jane Doe for James Doe' in resp.text
assert 'February 2022' in resp.text
assert 'Configuration is not completed yet.' in resp.text
@ -215,8 +219,9 @@ def test_shared_custody_agenda_month_view(app, admin_user):
def test_shared_custody_agenda_month_view_date_start(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=datetime.date(2022, 1, 1)
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)))
@ -252,8 +257,9 @@ def test_shared_custody_agenda_month_view_date_start(app, admin_user):
def test_shared_custody_agenda_month_view_queries(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
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')
@ -285,14 +291,15 @@ def test_shared_custody_agenda_month_view_queries(app, admin_user):
with CaptureQueriesContext(connection) as ctx:
app.get('/manage/shared-custody/%s/2022/12/' % agenda.pk)
assert len(ctx.captured_queries) == 9
assert len(ctx.captured_queries) == 10
def test_shared_custody_agenda_holiday_rules(app, admin_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
app = login(app)
@ -399,8 +406,9 @@ def test_shared_custody_settings_feature_flag(app, admin_user, settings):
def test_shared_custody_settings_management_role(app, admin_user, manager_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
app = login(app, username='manager', password='manager')
@ -422,8 +430,9 @@ def test_shared_custody_settings_management_role(app, admin_user, manager_user):
def test_shared_custody_agenda_delete(app, admin_user, manager_user):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodySettings.objects.create(management_role=manager_user.groups.all()[0])

View File

@ -2771,8 +2771,9 @@ def test_recurring_events_create_past_recurrences(freezer):
def test_shared_custody_agenda():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, days=list(range(7)), weeks='even', guardian=father)
@ -2829,8 +2830,9 @@ def test_shared_custody_agenda():
def test_shared_custody_agenda_different_periodicity():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
SharedCustodyRule.objects.create(agenda=agenda, days=[1, 2, 3], guardian=father)
@ -2880,8 +2882,9 @@ def test_shared_custody_agenda_different_periodicity():
def test_shared_custody_agenda_is_complete(rules, complete):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
for i, rule in enumerate(rules):
@ -2912,8 +2915,9 @@ def test_shared_custody_agenda_is_complete(rules, complete):
def test_shared_custody_agenda_rule_overlaps(rules, days, weeks, overlaps):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
for i, rule in enumerate(rules):
@ -2928,8 +2932,9 @@ def test_shared_custody_agenda_holiday_rule_overlaps():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
summer_holiday = TimePeriodExceptionGroup.objects.create(
@ -3000,8 +3005,9 @@ def test_shared_custody_agenda_holiday_rule_overlaps():
def test_shared_custody_agenda_period_overlaps(periods, date_start, date_end, overlaps):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
for i, dates in enumerate(periods):
@ -3018,8 +3024,9 @@ def test_shared_custody_agenda_period_holiday_rule_no_overlaps():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
summer_holiday = TimePeriodExceptionGroup.objects.create(
@ -3037,8 +3044,9 @@ def test_shared_custody_agenda_period_holiday_rule_no_overlaps():
def test_shared_custody_agenda_rule_label():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
rule = SharedCustodyRule.objects.create(agenda=agenda, guardian=father, days=list(range(7)))
@ -3071,8 +3079,9 @@ def test_shared_custody_agenda_holiday_rule_label():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
summer_holiday = TimePeriodExceptionGroup.objects.create(
@ -3111,8 +3120,9 @@ def test_shared_custody_agenda_holiday_rule_label():
def test_shared_custody_agenda_period_label(freezer):
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
period = SharedCustodyPeriod.objects.create(
@ -3133,8 +3143,9 @@ def test_shared_custody_agenda_holiday_rule_create_periods():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
summer_holiday = TimePeriodExceptionGroup.objects.create(
@ -3238,8 +3249,9 @@ def test_shared_custody_agenda_holiday_rule_create_periods_christmas_holidays():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
christmas_holiday = TimePeriodExceptionGroup.objects.create(
@ -3300,8 +3312,9 @@ def test_shared_custody_agenda_holiday_rules_application():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
christmas_holiday = TimePeriodExceptionGroup.objects.create(
@ -3349,8 +3362,9 @@ def test_shared_custody_agenda_update_holiday_rules_command():
father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
child = Person.objects.create(user_external_id='child_id', first_name='James', last_name='Doe')
agenda = SharedCustodyAgenda.objects.create(
first_guardian=father, second_guardian=mother, date_start=now()
first_guardian=father, second_guardian=mother, child=child, date_start=now()
)
christmas_holiday = TimePeriodExceptionGroup.objects.create(