Project

General

Profile

0001-api-ignore-guardian_external_id-when-child-has-no-cu.patch

Valentin Deniaud, 06 July 2022 02:28 PM

Download (2.44 KB)

View differences:

Subject: [PATCH] api: ignore guardian_external_id when child has no custody
 agenda (#66828)

 chrono/agendas/models.py                            | 9 +++++++--
 tests/api/datetimes/test_events_multiple_agendas.py | 7 +++++++
 2 files changed, 14 insertions(+), 2 deletions(-)
chrono/agendas/models.py
824 824

  
825 825
    @staticmethod
826 826
    def filter_for_guardian(qs, guardian_external_id, child_external_id):
827
        agendas = SharedCustodyAgenda.objects.filter(children__user_external_id=child_external_id)
827
        agendas = SharedCustodyAgenda.objects.filter(children__user_external_id=child_external_id).order_by(
828
            '-date_start'
829
        )
830
        if not agendas:
831
            return qs
832

  
828 833
        qs = (
829 834
            qs.annotate(week=ExtractWeek('start_datetime'))
830 835
            .annotate(week_number=Cast('week', models.IntegerField()))
......
833 838

  
834 839
        previous_date_start = None
835 840
        filtered_qs = Event.objects.none()
836
        for agenda in agendas.order_by('-date_start'):
841
        for agenda in agendas:
837 842
            filtered_qs |= Agenda.filter_for_custody_agenda(
838 843
                qs, agenda, guardian_external_id, date_end=previous_date_start
839 844
            )
tests/api/datetimes/test_events_multiple_agendas.py
720 720
    )
721 721
    assert len(resp.json['data']) == 2
722 722

  
723
    # guardian_external_id parameter is ignored if there is no custody agenda for child
724
    resp = app.get(
725
        '/api/agendas/datetimes/?guardian_external_id=xxx',
726
        params={'subscribed': 'all', 'user_external_id': 'child_id'},
727
    )
728
    assert len(resp.json['data']) == 2
729

  
723 730
    # add shared custody agenda
724 731
    father = Person.objects.create(user_external_id='father_id', first_name='John', last_name='Doe')
725 732
    mother = Person.objects.create(user_external_id='mother_id', first_name='Jane', last_name='Doe')
726
-