From c4a71ede04403febaa3179f52db68352be6764dd Mon Sep 17 00:00:00 2001 From: Nicolas ROCHE Date: Fri, 20 Jan 2023 21:27:38 +0100 Subject: [PATCH] toulouse-maelis: add ActivityNatureType referential (#73647) --- passerelle/contrib/toulouse_maelis/models.py | 16 ++ .../R_read_activity_nature_type_list.xml | 142 ++++++++++++++++++ tests/test_toulouse_maelis.py | 40 +++++ 3 files changed, 198 insertions(+) create mode 100644 tests/data/toulouse_maelis/R_read_activity_nature_type_list.xml diff --git a/passerelle/contrib/toulouse_maelis/models.py b/passerelle/contrib/toulouse_maelis/models.py index 1949c4d8..c58f5a58 100644 --- a/passerelle/contrib/toulouse_maelis/models.py +++ b/passerelle/contrib/toulouse_maelis/models.py @@ -161,10 +161,17 @@ class ToulouseMaelis(BaseResource, HTTPResource): id_key, text_key = 'schoolYear', 'schoolYear' self.update_referential(referential_name, data, id_key, text_key) + def update_activity_referentials(self): + for referential_name in ('ActivityNatureType',): + id_key, text_key = 'code', 'libelle' + data = self.get_referential_data('Activity', referential_name) + self.update_referential(referential_name, data, id_key, text_key) + def daily(self): try: self.update_family_referentials() self.update_site_referentials() + self.update_activity_referentials() except UpdateError as e: self.logger.warning('Erreur sur la mise à jour: %s' % e) @@ -2400,6 +2407,15 @@ class ToulouseMaelis(BaseResource, HTTPResource): ) return geojson + @endpoint( + display_category='Inscriptions', + description="Liste des natures des activités", + name='read-activity-nature-list', + perm='can_access', + ) + def read_activity_nature_list(self, request): + return {'data': self.get_referential('ActivityNatureType')} + class Link(models.Model): resource = models.ForeignKey(ToulouseMaelis, on_delete=models.CASCADE) diff --git a/tests/data/toulouse_maelis/R_read_activity_nature_type_list.xml b/tests/data/toulouse_maelis/R_read_activity_nature_type_list.xml new file mode 100644 index 00000000..a063c642 --- /dev/null +++ b/tests/data/toulouse_maelis/R_read_activity_nature_type_list.xml @@ -0,0 +1,142 @@ + + + + + A + Accueil Périscolaire + + ACCMAT + Accueil du matin + + + ACCMIDI + Accueil du mercredi + + + ACCPERI + Accueil périscolaire + + + ACCSOIR + Accueil du soir + + + + P + Loisirs + + AIAR + ART DE L'IMAGE - ACTIVITE REGULIERE + + + APS + ART PLASTIQUE - SORTIE + + + CIS + CIRQUE - SORTIE + + + CS + CULTURE - SORTIE + + + DS + DANSE - SORTIE + + + LOI_ADU + Loisirs Adultes + + + MS + MUSIQUE - SORTIE + + + MSE + MUSIQUE - SEJOUR + + + RS + RANDONNEE - SORTIE + + + SAR + SPORT - ACTIVITE REGULIERE + + + SST + SPORT - STAGE + + + + E + Petite Enfance + + CRECHCO + Crèche collective + + + CRECHFAM + Crèche familiale + + + HALTG + Halte garderie + + + MA + Multi accueil + + + + L + Loisirs Enfants + + LOI_ANN + Loisirs Enfants - Annuel + + + LOI_SOR + Loisirs - Sortie + + + LOI_STA + Loisirs - Stage + + + + S + Loisirs Senior + + LOI_SEN + Loisirs Senior + + + + V + Vacances Enfants + + LOI_VAC + Loisirs - Vacances + + + + R + Restauration Scolaire + + RESTENS + Restauration enseignant + + + RESTSCOL + Restauration scolaire enfant + + + RESTSEN + Restauration Senior + + + + + diff --git a/tests/test_toulouse_maelis.py b/tests/test_toulouse_maelis.py index 86b8b4a4..0ef01cdf 100644 --- a/tests/test_toulouse_maelis.py +++ b/tests/test_toulouse_maelis.py @@ -134,6 +134,13 @@ def django_db_setup(django_db_setup, django_db_blocker): wsdl_content=get_xml_file('FamilyService.wsdl'), settings=Settings(strict=False, xsd_ignore_sequence_order=True), ) + + activity_service = ResponsesSoap( + wsdl_url='https://example.org/ActivityService?wsdl', + wsdl_content=get_xml_file('ActivityService.wsdl'), + settings=Settings(strict=False, xsd_ignore_sequence_order=True), + ) + with family_service() as soap_mock: soap_mock.add_soap_response('readCategoryList', get_xml_file('R_read_category_list.xml')) soap_mock.add_soap_response( @@ -158,6 +165,11 @@ def django_db_setup(django_db_setup, django_db_blocker): site_mock.add_soap_response('readLevelList', get_xml_file('R_read_level_list.xml')) site_mock.add_soap_response('readDerogReasonList', get_xml_file('R_read_derog_reason_list.xml')) con.update_site_referentials() + with activity_service() as activity_mock: + activity_mock.add_soap_response( + 'readActivityNatureTypeList', get_xml_file('R_read_activity_nature_type_list.xml') + ) + con.update_activity_referentials() # reset change in zeep private interface to bypass clear_cache fixture from zeep.cache import InMemoryCache @@ -312,6 +324,7 @@ def test_update_referential(mocked_get, con): def test_cron(db): assert Referential.objects.filter(referential_name='Category').count() == 3 assert sorted(list({x.referential_name for x in Referential.objects.all()})) == [ + 'ActivityNatureType', 'CSP', 'Category', 'ChildIndicator', @@ -5242,3 +5255,30 @@ def test_get_person_catalog_geojson_date_error(con, app): resp = app.get(url, params=params, status=400) assert resp.json['err'] == 'bad-request' assert resp.json['err_desc'] == 'start_date and end_date are in different reference year (2022 != 2023)' + + +def test_read_activity_nature_list(con, app): + url = get_endpoint('read-activity-nature-list') + resp = app.get(url) + assert resp.json['err'] == 0 + assert [(x['id'], x['text']) for x in resp.json['data']] == [ + ('A', 'Accueil Périscolaire'), + ('P', 'Loisirs'), + ('L', 'Loisirs Enfants'), + ('S', 'Loisirs Senior'), + ('E', 'Petite Enfance'), + ('R', 'Restauration Scolaire'), + ('V', 'Vacances Enfants'), + ] + assert resp.json['data'][0] == { + 'id': 'A', + 'code': 'A', + 'text': 'Accueil Périscolaire', + 'libelle': 'Accueil Périscolaire', + 'activityTypeList': [ + {'code': 'ACCMAT', 'libelle': 'Accueil du matin'}, + {'code': 'ACCMIDI', 'libelle': 'Accueil du mercredi'}, + {'code': 'ACCPERI', 'libelle': 'Accueil périscolaire'}, + {'code': 'ACCSOIR', 'libelle': 'Accueil du soir'}, + ], + }