diff --git a/passerelle/contrib/toulouse_axel/models.py b/passerelle/contrib/toulouse_axel/models.py
index 69f5f5ca..e218aca3 100644
--- a/passerelle/contrib/toulouse_axel/models.py
+++ b/passerelle/contrib/toulouse_axel/models.py
@@ -861,9 +861,11 @@ class ToulouseAxel(BaseResource):
# exclude child in private schools
if child['LIBELLEECOLE'].startswith('PRIVEE'):
continue
- # exclude also child with more than one registration per activity_type
+ # exclude also child with more than one registration per activity_type or missing activity
activity_types = [a['TYPEACTIVITE'] for a in child.get('ACTIVITE', [])]
- if len(activity_types) > len(set(activity_types)):
+ activity_types.sort()
+ if activity_types != ['MAT', 'MIDI', 'SOIR'] and activity_types != ['GARD', 'MAT', 'MIDI', 'SOIR']:
+ # GARD is optional
continue
# ok, store child
data[child['IDPERSONNE']] = child
diff --git a/tests/data/toulouse_axel/child_activities.xml b/tests/data/toulouse_axel/child_activities.xml
index e10b564b..c7142028 100644
--- a/tests/data/toulouse_axel/child_activities.xml
+++ b/tests/data/toulouse_axel/child_activities.xml
@@ -114,61 +114,5 @@
31/07/2020
-
- foo
- foo
- 01/01/2019
- 1234
- SV
- MATERNELLE 42
-
- MAT
- A19P1M1
- Temps du matin
- 01/08/2019
- 31/07/2020
- 0.42
- NON
- 99999
- 01/08/2019
- 31/07/2020
-
-
- MAT
- A19P1M1bis
- Temps du matin autre école
- 01/08/2019
- 31/07/2020
- 0.43
- NON
- 99999
- 01/08/2019
- 31/07/2020
-
-
- SOIR
- A19P1M3
- Temps du soir
- 01/08/2019
- 31/07/2020
- 0.44
- NON
- 99999
- 01/08/2019
- 31/07/2020
-
-
- GARD
- A19P1M4
- Temps mercredi après midi
- 01/08/2019
- 31/07/2020
- 0.45
- NON
- 99999
- 01/08/2019
- 31/07/2020
-
-
diff --git a/tests/test_toulouse_axel.py b/tests/test_toulouse_axel.py
index 4167398d..c8ce3191 100644
--- a/tests/test_toulouse_axel.py
+++ b/tests/test_toulouse_axel.py
@@ -2424,6 +2424,36 @@ def test_clae_children_activities_info_endpoint(app, resource):
assert resp.json['err'] == 0
+@pytest.mark.parametrize('activities, expected', [
+ # all activities except GARD - optional
+ (['MAT', 'MIDI', 'SOIR'], True),
+ # all activities
+ (['MAT', 'MIDI', 'SOIR', 'GARD'], True),
+ # duplicated activities
+ (['MAT', 'MAT', 'MIDI', 'SOIR', 'GARD'], False),
+ (['MAT', 'MIDI', 'MIDI', 'SOIR', 'GARD'], False),
+ (['MAT', 'MIDI', 'SOIR', 'SOIR', 'GARD'], False),
+ (['MAT', 'MIDI', 'SOIR', 'GARD', 'GARD'], False),
+ # missing activity
+ (['MIDI', 'SOIR'], False),
+ (['MAT', 'SOIR'], False),
+ (['MAT', 'MIDI'], False),
+])
+def test_clae_children_activities_info_check(app, resource, activities, expected):
+ Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
+ result = []
+ for activity in activities:
+ result.append({'IDACTIVITE': 'foo%s' % activity, 'TYPEACTIVITE': activity})
+ result = {'DATA': {'PORTAIL': {'DUI': {'ENFANT': [
+ {'IDPERSONNE': '42', 'NOM': '', 'PRENOM': '', 'REGIME': '', 'LIBELLEECOLE': '', 'ACTIVITE': result}
+ ]}}}}
+ with mock.patch('passerelle.contrib.toulouse_axel.schemas.enfants_activites') as operation:
+ operation.return_value = schemas.OperationResult(json_response=result, xml_request='', xml_response='')
+ resp = app.get('/toulouse-axel/test/clae_children_activities_info?NameID=yyy&booking_date=2020-01-20')
+ assert resp.json['err'] == 0
+ assert len(resp.json['data']) == expected and 1 or 0
+
+
def test_clae_booking_activities_info_endpoint_axel_error(app, resource):
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
with mock.patch('passerelle.contrib.toulouse_axel.schemas.enfants_activites') as operation: