From a95c124ba7581e2488d03110fe60cafa14cfc670 Mon Sep 17 00:00:00 2001 From: Victor Perron Date: Wed, 18 Sep 2024 15:27:57 +0200 Subject: [PATCH] __wip : test unitaire --- pipeline/dbt/models/intermediate/_models.yml | 36 ++++++ .../.~lock.zone_diffusion_adresses.csv# | 1 + .../.~lock.zone_diffusion_services.csv# | 1 + .../.~lock.zone_diffusion_structures.csv# | 1 + .../fixtures/zone_diffusion_adresses.csv | 4 + .../fixtures/zone_diffusion_services.sql | 113 ++++++++++++++++++ .../fixtures/zone_diffusion_structures.csv | 4 + 7 files changed, 160 insertions(+) create mode 100644 pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_adresses.csv# create mode 100644 pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_services.csv# create mode 100644 pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_structures.csv# create mode 100644 pipeline/dbt/tests/fixtures/zone_diffusion_adresses.csv create mode 100644 pipeline/dbt/tests/fixtures/zone_diffusion_services.sql create mode 100644 pipeline/dbt/tests/fixtures/zone_diffusion_structures.csv diff --git a/pipeline/dbt/models/intermediate/_models.yml b/pipeline/dbt/models/intermediate/_models.yml index 6675631f..3ac43d61 100644 --- a/pipeline/dbt/models/intermediate/_models.yml +++ b/pipeline/dbt/models/intermediate/_models.yml @@ -69,3 +69,39 @@ models: * geocoded addresses * email with pii flag + +unit_tests: +- name: test_zone_diffusion_is_correctly_filled + model: int__union_services__enhanced + overrides: + macros: + dbt_utils.star: '*' + given: + - input: ref('stg_decoupage_administratif__departements') + rows: + - {code: '75', nom: 'Paris'} + - {code: '974', nom: 'La Réunion'} + - input: ref('int__union_structures__enhanced') + format: sql + rows: + select '1' as _di_surrogate_id, 'monenfant' as source, '22 rue Sainte-Marthe' as adresse + union all + select '2' as _di_surrogate_id, 'soliguide' as source, '3 Rpe des Mobiles' as adresse + union all + select '3' as _di_surrogate_id, 'dora' as source, null as adresse + - input: ref('int__union_adresses__enhanced') + rows: + - {_di_surrogate_id: '1', code_insee: '75101'} + - {_di_surrogate_id: '2', code_insee: '97423'} + - {_di_surrogate_id: '3', code_insee: null} + - input: ref('int__union_services') + format: sql + fixture: zone_diffusion_services + expect: + rows: + - {adresse: '22 rue Sainte-Marthe'} + - {adresse: '3 Rpe des Mobiles'} + - {adresse: null} + - {adresse: null} + - {adresse: '36 Rte de Toulon'} + diff --git a/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_adresses.csv# b/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_adresses.csv# new file mode 100644 index 00000000..93a9ee12 --- /dev/null +++ b/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_adresses.csv# @@ -0,0 +1 @@ +,victor,W,18.09.2024 15:03,file:///home/victor/.config/libreoffice/4; \ No newline at end of file diff --git a/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_services.csv# b/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_services.csv# new file mode 100644 index 00000000..93a9ee12 --- /dev/null +++ b/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_services.csv# @@ -0,0 +1 @@ +,victor,W,18.09.2024 15:03,file:///home/victor/.config/libreoffice/4; \ No newline at end of file diff --git a/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_structures.csv# b/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_structures.csv# new file mode 100644 index 00000000..93a9ee12 --- /dev/null +++ b/pipeline/dbt/tests/fixtures/.~lock.zone_diffusion_structures.csv# @@ -0,0 +1 @@ +,victor,W,18.09.2024 15:03,file:///home/victor/.config/libreoffice/4; \ No newline at end of file diff --git a/pipeline/dbt/tests/fixtures/zone_diffusion_adresses.csv b/pipeline/dbt/tests/fixtures/zone_diffusion_adresses.csv new file mode 100644 index 00000000..6905997d --- /dev/null +++ b/pipeline/dbt/tests/fixtures/zone_diffusion_adresses.csv @@ -0,0 +1,4 @@ +_di_surrogate_id,id,source,complement_adresse,adresse,longitude,latitude,commune,code_postal,code_insee,result_score +1,1,dora,VILTAIS ACCUEIL LOGEMENT,8 Rue Ernest Montuses,2.618378,46.324104,Montluçon,3100,3185,0.968204545454545 +2,2,dora,,18 Rue Charles Baudelaire,3.906533,50.257305,Hautmont,59330,59291,0.960154545454545 +3,3,mediation-numerique,,8 Grand Rue,-0.74859,46.923074,Mauléon,79700,79079,0.965628181818182 diff --git a/pipeline/dbt/tests/fixtures/zone_diffusion_services.sql b/pipeline/dbt/tests/fixtures/zone_diffusion_services.sql new file mode 100644 index 00000000..751c6d0b --- /dev/null +++ b/pipeline/dbt/tests/fixtures/zone_diffusion_services.sql @@ -0,0 +1,113 @@ +select + '1' as _di_surrogate_id, + '1' as _di_adresse_surrogate_id, + '1' as _di_structure_surrogate_id, + '1' as id, + '1' as structure_id, + 'Mon premier service' as nom, + 'monenfant' as source, + '75101' as zone_diffusion_code, + 'commune' as zone_diffusion_type, + 'Paris' as zone_diffusion_nom, + true as contact_public, + 'Jean Mermoz' as contact_nom_prenom, + 'jean@mermoz.net' as courriel, + true as cumulable, + NULL as date_creation, + NULL as date_suspension, + NULL as frais, + NULL as frais_autres, + NULL as justificatifs, + NULL as lien_source, + NULL as modes_accueil, + NULL as modes_orientation_accompagnateur, + NULL as modes_orientation_accompagnateur_autres, + NULL as modes_orientation_beneficiaire, + NULL as modes_orientation_beneficiaire_autres, + NULL as page_web, + NULL as presentation_detail, + NULL as presentation_resume, + NULL as prise_rdv, + NULL as profils, + NULL as recurrence, + NULL as telephone, + NULL as thematiques, + NULL as types, + NULL as pre_requis, + CURRENT_DATE as date_maj +union all +select + '2' as _di_surrogate_id, + '2' as _di_adresse_surrogate_id, + '2' as _di_structure_surrogate_id, + '2' as id, + '2' as structure_id, + 'Un super service' as nom, + 'soliguide' as source, + '97423' as zone_diffusion_code, + 'commune' as zone_diffusion_type, + 'La Réunion' as zone_diffusion_nom, + true as contact_public, + 'Léa Salami' as contact_nom_prenom, + 'lea.salami@gmail.com' as courriel, + true as cumulable, + NULL as date_creation, + NULL as date_suspension, + NULL as frais, + NULL as frais_autres, + NULL as justificatifs, + NULL as lien_source, + NULL as modes_accueil, + NULL as modes_orientation_accompagnateur, + NULL as modes_orientation_accompagnateur_autres, + NULL as modes_orientation_beneficiaire, + NULL as modes_orientation_beneficiaire_autres, + NULL as page_web, + NULL as presentation_detail, + NULL as presentation_resume, + NULL as prise_rdv, + NULL as profils, + NULL as recurrence, + NULL as telephone, + NULL as thematiques, + NULL as types, + NULL as pre_requis, + CURRENT_DATE as date_maj +union all +select + '3' as _di_surrogate_id, + '3' as _di_adresse_surrogate_id, + '3' as _di_structure_surrogate_id, + '3' as id, + '3' as structure_id, + 'Mon dernier service' as nom, + 'dora' as source, + '974' as zone_diffusion_code, + 'departement' as zone_diffusion_type, + 'La Réunion' as zone_diffusion_nom, + true as contact_public, + NULL as contact_nom_prenom, + NULL as courriel, + false as cumulable, + NULL as date_creation, + NULL as date_suspension, + NULL as frais, + NULL as frais_autres, + NULL as justificatifs, + NULL as lien_source, + NULL as modes_accueil, + NULL as modes_orientation_accompagnateur, + NULL as modes_orientation_accompagnateur_autres, + NULL as modes_orientation_beneficiaire, + NULL as modes_orientation_beneficiaire_autres, + NULL as page_web, + NULL as presentation_detail, + NULL as presentation_resume, + NULL as prise_rdv, + NULL as profils, + NULL as recurrence, + NULL as telephone, + NULL as thematiques, + NULL as types, + NULL as pre_requis, + CURRENT_DATE as date_maj diff --git a/pipeline/dbt/tests/fixtures/zone_diffusion_structures.csv b/pipeline/dbt/tests/fixtures/zone_diffusion_structures.csv new file mode 100644 index 00000000..7f855159 --- /dev/null +++ b/pipeline/dbt/tests/fixtures/zone_diffusion_structures.csv @@ -0,0 +1,4 @@ +accessibilite,adresse_id,antenne,courriel,horaires_ouverture,id,labels_autres,labels_nationaux,lien_source,nom,presentation_detail,presentation_resume,rna,siret,site_web,source,telephone,typologie,date_maj,thematiques,_di_surrogate_id,_di_adresse_surrogate_id,longitude,latitude,complement_adresse,commune,adresse,code_postal,code_insee,_di_geocodage_score,_di_email_is_pii +,1,f,,,1,{},{conseiller-numerique},https://dora.inclusion.beta.gouv.fr/structures/le-mans-metropole-co,LE MANS METROPOLE COMMUNAUTE URBAINE,,,,24720013200014,,dora,,,2022-09-29,,1,1,0.19695,48.007479,1 - 2,Le Mans,1 PL SAINT PIERRE,72039,72181,,f +https://www.pole-emploi.fr/actualites/a-laffiche/2022/adeda-un-dispositif-pour-mieux-a.html,2,f,,,2,,{france-travail},,Agence France Travail CHARLEVILLE-MEZIERES VAL DE VENCE,,,,13000548120281,https://www.francetravail.fr,france-travail,3949,FT,2024-09-17,,2,2,4.729209,49.742055,,Charleville-Mézières,6 Rue Jean-baptiste Lefort,8000,8105,0.966555454545454,f +,3,,,,3,{ZRR},{conseiller-numerique},,Médiathèque du Haut-Verdon,,,,,https://www.ccapv.fr/services-publics/france-services/conseils-numeriques,mediation-numerique,,BIB,2024-06-27,"{numerique,numerique--prendre-en-main-un-smartphone-ou-une-tablette,numerique--prendre-en-main-un-ordinateur,numerique--utiliser-le-numerique-au-quotidien,numerique--approfondir-ma-culture-numerique,numerique--accompagner-les-demarches-de-sante}",3,3,6.628006,44.240556,,Allos,Grand Rue,4260,4006,0.951707272727273,f