From f0f97a3bf98326680c16fc8524960090814a0922 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Laur=C3=A9line=20Gu=C3=A9rin?= <zebuline@entrouvert.com>
Date: Tue, 7 Apr 2020 10:22:32 +0200
Subject: [PATCH] toulouse-axel: remove all about next year (#41406)

---
 passerelle/contrib/toulouse_axel/models.py | 23 ++---------
 tests/test_toulouse_axel.py                | 46 ++++++----------------
 2 files changed, 17 insertions(+), 52 deletions(-)

diff --git a/passerelle/contrib/toulouse_axel/models.py b/passerelle/contrib/toulouse_axel/models.py
index 6b5b23e6..a05eacf6 100644
--- a/passerelle/contrib/toulouse_axel/models.py
+++ b/passerelle/contrib/toulouse_axel/models.py
@@ -518,16 +518,10 @@ class ToulouseAxel(BaseResource):
         current_reference_year = utils.get_reference_year_from_date(today)
         next_reference_year = current_reference_year + 1
         if check_registrations:
-            children_registred_for_current_year = self.are_children_registered(
-                dui=dui,
-                reference_year=current_reference_year)
-            children_registred_for_next_year = self.are_children_registered(
-                dui=dui,
-                reference_year=next_reference_year)
+            children_registred = self.are_children_registered(dui=dui)
 
             for child in family_data.get('ENFANT', []):
-                child['clae_cantine_current'] = children_registred_for_current_year.get(child['IDPERSONNE'])
-                child['clae_cantine_next'] = children_registred_for_next_year.get(child['IDPERSONNE'])
+                child['clae_cantine_current'] = children_registred.get(child['IDPERSONNE'])
 
         if with_management_dates:
             family_data['management_dates'] = self.get_management_dates()
@@ -1043,19 +1037,10 @@ class ToulouseAxel(BaseResource):
 
         return children_activities[child_id]
 
-    def are_children_registered(self, dui, reference_year):
+    def are_children_registered(self, dui):
         # check reference_year
         today = datetime.date.today()
-        current_reference_year = utils.get_reference_year_from_date(today)
-        # don't check registration for other years than current and next
-        if reference_year not in [current_reference_year, current_reference_year + 1]:
-            return {}
-        # if next year, check dates.
-        # check registration for next year only in june or july
-        if reference_year == current_reference_year + 1 and today.month not in [6, 7]:
-            return {}
-
-        # ok, check registrations
+        reference_year = utils.get_reference_year_from_date(today)
         try:
             children_activities = self.get_children_activities(dui=dui, reference_year=reference_year)
         except APIError:
diff --git a/tests/test_toulouse_axel.py b/tests/test_toulouse_axel.py
index fd421243..9a9d7890 100644
--- a/tests/test_toulouse_axel.py
+++ b/tests/test_toulouse_axel.py
@@ -52,7 +52,6 @@ from passerelle.contrib.toulouse_axel.utils import (
     csp_mapping,
     lien_parente_mapping,
     type_regime_mapping,
-    get_reference_year_from_date,
     upperize,
 )
 from passerelle.utils.jsonresponse import APIError
@@ -777,28 +776,24 @@ def test_family_info_endpoint(app, resource):
     assert resp.json['data']['annee_reference_label'] == '2019/2020'
 
     with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.are_children_registered') as registered:
-        registered.side_effect = [{'4242': True}, {}]
+        registered.return_value = {'4242': True}
         with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_management_dates') as management_dates:
             management_dates.return_value = {'foo': 'bar'}
             with mock_getdata(content, 'RefFamilleDui'):
                 resp = app.get('/toulouse-axel/test/family_info?NameID=yyy')
     assert resp.json['err'] == 0
     assert resp.json['data']['ENFANT'][0]['clae_cantine_current'] is True
-    assert resp.json['data']['ENFANT'][0]['clae_cantine_next'] is None
     assert resp.json['data']['ENFANT'][1]['clae_cantine_current'] is None
-    assert resp.json['data']['ENFANT'][1]['clae_cantine_next'] is None
 
     with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.are_children_registered') as registered:
-        registered.side_effect = [{}, {'4242': False, '3535': True}]
+        registered.return_value = {}
         with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_management_dates') as management_dates:
             management_dates.return_value = {'foo': 'bar'}
             with mock_getdata(content, 'RefFamilleDui'):
                 resp = app.get('/toulouse-axel/test/family_info?NameID=yyy')
     assert resp.json['err'] == 0
     assert resp.json['data']['ENFANT'][0]['clae_cantine_current'] is None
-    assert resp.json['data']['ENFANT'][0]['clae_cantine_next'] is False
     assert resp.json['data']['ENFANT'][1]['clae_cantine_current'] is None
-    assert resp.json['data']['ENFANT'][1]['clae_cantine_next'] is True
 
     assert resp.json['data']['SITUATIONFAMILIALE'] == 'S'
     assert resp.json['data']['SITUATIONFAMILIALE_label'] == 'Séparé (e)'
@@ -899,7 +894,6 @@ def test_child_info_endpoint(app, resource):
         'SANITAIRE',
         'SEXE',
         'clae_cantine_current',
-        'clae_cantine_next',
     ])
     assert resp.json['data']['id'] == '4242'
     assert resp.json['data']['text'] == 'foo foo'
@@ -911,20 +905,18 @@ def test_child_info_endpoint(app, resource):
     assert resp.json['data']['CONTACT'][2]['text'] == 'foo foo'
 
     with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.are_children_registered') as registered:
-        registered.side_effect = [{'4242': True}, {}]
+        registered.return_value = {'4242': True}
         with mock_getdata(content, 'RefFamilleDui'):
             resp = app.get('/toulouse-axel/test/child_info?NameID=yyy&idpersonne=4242')
     assert resp.json['err'] == 0
     assert resp.json['data']['clae_cantine_current'] is True
-    assert resp.json['data']['clae_cantine_next'] is None
 
     with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.are_children_registered') as registered:
-        registered.side_effect = [{}, {'4242': False}]
+        registered.return_value = {}
         with mock_getdata(content, 'RefFamilleDui'):
             resp = app.get('/toulouse-axel/test/child_info?NameID=yyy&idpersonne=4242')
     assert resp.json['err'] == 0
     assert resp.json['data']['clae_cantine_current'] is None
-    assert resp.json['data']['clae_cantine_next'] is False
 
     assert resp.json['data']['CONTACT'][0]['LIENPARENTE'] == 'GRP1'
     assert resp.json['data']['CONTACT'][0]['LIENPARENTE_label'] == 'Grands-parents paternels'
@@ -2773,29 +2765,18 @@ def test_clae_booking_activity_prefill_endpoint(app, resource, child_activities_
 def test_are_children_registered_axel_error(resource):
     with mock.patch('passerelle.contrib.toulouse_axel.models.enfants_activites') as operation:
         operation.side_effect = AxelError('FooBar')
-        assert resource.are_children_registered(dui='XXX', reference_year=42) == {}
-
-
-@pytest.mark.parametrize('date_value, year, expected', [
-    # neither current year nor next year
-    ('2020-01-01', 2018, {}),
-    ('2020-01-01', 2021, {}),
-    # current year
-    ('2019-08-01', 2019, {'3535': True}),
-    ('2020-07-31', 2019, {'3535': True}),
-    # too early for next_year
-    ('2019-08-01', 2020, {}),
-    ('2020-01-01', 2020, {}),
-    ('2020-05-31', 2020, {}),
-    # good period for next year
-    ('2020-06-01', 2020, {'3535': True}),
-    ('2020-07-31', 2020, {'3535': True}),
+        assert resource.are_children_registered(dui='XXX') == {}
+
+
+@pytest.mark.parametrize('date_value, expected', [
+    ('2019-08-01', {'3535': True}),
+    ('2020-07-31', {'3535': True}),
 ])
-def test_are_children_registered_reference_year(resource, date_value, year, expected):
+def test_are_children_registered_reference_year(resource, date_value, expected):
     with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_children_activities') as get_children_activities:
         get_children_activities.return_value = {'3535': {'ACTIVITE': [{}]}}
         with freezegun.freeze_time(date_value):
-            assert resource.are_children_registered(dui='XXX', reference_year=year) == expected
+            assert resource.are_children_registered(dui='XXX') == expected
 
 
 @pytest.mark.parametrize('activities, expected', [
@@ -2805,10 +2786,9 @@ def test_are_children_registered_reference_year(resource, date_value, year, expe
     ({'3535': {'ACTIVITE': [{}]}, '4242': {}}, {'3535': True, '4242': False}),
 ])
 def test_are_children_registered(resource, activities, expected):
-    today = datetime.date.today()
     with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_children_activities') as get_children_activities:
         get_children_activities.return_value = activities
-        assert resource.are_children_registered(dui='XXX', reference_year=get_reference_year_from_date(today)) == expected
+        assert resource.are_children_registered(dui='XXX') == expected
 
 
 def test_clae_booking_endpoint_axel_error(app, resource, booking_params):
-- 
2.20.1

