diff --git a/backend/geonature/core/imports/checks/sql/nomenclature.py b/backend/geonature/core/imports/checks/sql/nomenclature.py index 23d2a2e349..948e14a2c5 100644 --- a/backend/geonature/core/imports/checks/sql/nomenclature.py +++ b/backend/geonature/core/imports/checks/sql/nomenclature.py @@ -16,6 +16,7 @@ "check_nomenclature_exist_proof", "check_nomenclature_blurring", "check_nomenclature_source_status", + "check_nomenclature_technique_collect", ] @@ -149,3 +150,27 @@ def check_nomenclature_source_status(imprt, entity, source_status_field, ref_bib transient_table.c[ref_biblio_field.dest_field] == None, ), ) + + +def check_nomenclature_technique_collect( + imprt, entity, source_status_field, technical_precision_field +): + transient_table = imprt.destination.get_transient_table() + other = db.session.execute( + sa.select(TNomenclatures).where( + TNomenclatures.nomenclature_type.has( + BibNomenclaturesTypes.mnemonique == "TECHNIQUE_COLLECT_HAB" + ), + TNomenclatures.cd_nomenclature == "10", + ) + ).scalar_one() + report_erroneous_rows( + imprt, + entity, + error_type=ImportCodeError.CONDITIONAL_MANDATORY_FIELD_ERROR, + error_column=source_status_field.name_field, + whereclause=sa.and_( + transient_table.c[source_status_field.dest_field] == other.id_nomenclature, + transient_table.c[technical_precision_field.dest_field] == None, + ), + ) diff --git a/backend/geonature/tests/imports/files/occhab/valid_file.csv b/backend/geonature/tests/imports/files/occhab/valid_file.csv index d63e26fa8d..c3016c6b2e 100644 --- a/backend/geonature/tests/imports/files/occhab/valid_file.csv +++ b/backend/geonature/tests/imports/files/occhab/valid_file.csv @@ -1,40 +1,42 @@ -Objectif du test;Erreur station;Erreur habitat;id_station_source;unique_id_sinp_station;unique_dataset_id;date_min;date_max;observers;id_nomenclature_area_surface_calculation;WKT;id_nomenclature_geographic_object;unique_id_sinp_habitat;nom_cite;cd_hab;technical_precision -Station + habitat sur la même ligne;OK !;OK !;;afa81c29-c75d-408d-bf48-53cce02d5561;VALID_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;4ee53579-b09b-408f-aa1f-d62495a66667;prairie;24; -Station uniquement;OK !;Pas d’habitat;;9d3fb1bd-6148-45c4-aa13-ff9212155afe;VALID_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;;; -Habitat uniquement dans une station existante en base.;Pas de station;OK !;;EXISTING_STATION_UUID;;;;Toto;;;;05f0163a-ab14-4045-84b9-b513188092ae;prairie;24; -Dataset innexistant, habitat valide mais pas le parent;DATASET_NOT_FOUND(unique_dataset_id), INCOHERENT_DATA;ERRONEOUS_PARENT_ENTITY;;bdc3346d-0fc3-40fa-b787-be927e4dd82e;050d613c-543f-47fd-800a-13931b2721c7;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;2ff4867d-6943-45d8-873d-187fbc6d67a7;prairie;24; -Dataset interdit, habitat valide mais pas le parent;DATASET_NOT_AUTHORIZED(unique_dataset_id);ERRONEOUS_PARENT_ENTITY;;f5f031a3-cf1b-419c-9817-69c39f51aef4;FORBIDDEN_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;5dfb9930-4795-4e6f-baae-3dd86abb3b70;prairie;24; -Dataset UUID invalide;INVALID_UUID(unique_dataset_id);Pas d’habitat;;;erroneous;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);;;;; -Champs géométrique manquant;NO-GEOM(Champs géométriques);Pas d’habitat;;;;17/11/2023;17/11/2023;Toto;;;;;;; -Champs requis manquant;MISSING_VALUE(date_min);ERRONEOUS_PARENT_ENTITY;;4ee7728d-387d-49c5-b9a3-4162b0987fa5;;;;Toto;;POINT(3.634 44.399);St;aeb10ac4-6d69-4fa6-8df6-14d9304911df;prairie;24; -Habitat mais pas de station référencée;Pas de station;NO_PARENT_ENTITY(id_station);;;;;;Toto;;;;;prairie;24; -Uniquement un uuid station, mais on ne sait pas s’il appartient à une station ou s’il sert à indiquer le parent d’un habitat;ORPHAN_ROW(unique_id_sinp_station);ORPHAN_ROW(unique_id_sinp_station);;258a2478-8a0e-4321-83df-c2313ad3040e;;;;Toto;;;;;;; -Uniquement un id station source, mais on ne sait pas s’il appartient à une station ou s’il sert à indiquer le parent d’un habitat;ORPHAN_ROW(id_station_source);ORPHAN_ROW(id_station_source);Station -1;;;;;Toto;;;;;;; -Uniquement UUID station + id station source, mais on ne sait pas s’ils appartiennent à une station ou s’ils servent à indiquer le parent d’un habitat;ORPHAN_ROW(unique_id_sinp_station, id_station_source);ORPHAN_ROW(unique_id_sinp_station,id_station_source);Station -2;54e54935-982b-4da3-9aaf-e87e49a1fdf1;;;;Toto;;;;;;; -On importe 2 habitats dans une même nouvelle station dont les données sont répétées. Les lignes contenant la station sont rapproché par UUID.;OK !;OK !;;462d385f-489a-436b-babb-8cca5fc62e1d;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;e5e7a184-3e92-4adb-a721-5bd004b3397f;forêt;24; -;OK !;OK !;;462d385f-489a-436b-babb-8cca5fc62e1d;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;8f52f122-b9ae-45b3-b947-2c9f7934b823;prairie;24; -On importe 2 habitats dans une même nouvelle station dont les données sont répétées MAIS AVEC DES DIFFÉRENCES (date). Les lignes contenant la station sont rapproché par UUID.;INCOHERENT_DATA(unique_id_sinp_station);NO_PARENT_ENTITY(id_station);;74be5e79-72e7-42a8-ba2e-d5e27c9caddb;;17/11/2023;;Toto;;POINT(3.634 44.399);St;d91496e9-d904-45a8-9e18-cb8acbbb6ea6;prairie;24; -;INCOHERENT_DATA(unique_id_sinp_station);NO_PARENT_ENTITY(id_station);;74be5e79-72e7-42a8-ba2e-d5e27c9caddb;;18/11/2023;;Toto;;POINT(3.634 44.399);St;;prairie;24; -On importe 2 habitats dans une même nouvelle station dont les données sont répétées mais avec des différences (date INVALIDE). Les lignes contenant la station sont rapproché par UUID. On vérifie qu’on a pas d’erreur sur la date car les contrôles ne doivent pas être lancé si les données sont incohérentes. En revanche, les contrôles des habitats doivent bien être lancés.;INCOHERENT_DATA(unique_id_sinp_station);NO_PARENT_ENTITY(id_station);;74be5e79-72e7-42a8-ba2e-d5e27c9caddb;;17/11/2023;;Toto;;POINT(3.634 44.399);St;;prairie;24; -NO_PARENT_ENTITY(id_station) non levé sur l’habitat en raison de l’implémentation du check qui ignore les lignes erronées. À voir s’il faut le faire évoluer.;INCOHERENT_DATA(unique_id_sinp_station);INVALID_INTEGER(cd_hab);;74be5e79-72e7-42a8-ba2e-d5e27c9caddb;;date invalide;;Toto;;POINT(3.634 44.399);St;;prairie;invalide; -On importe 2 habitats dans une même nouvelle station dont les données sont répétées. Les lignes contenant la station sont rapproché par id origine.;OK !;OK !;Station 1;;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -;OK !;OK !;Station 1;;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -On importe 2 habitats dans une même nouvelle station dont les données sont répétées MAIS AVEC DES DIFFÉRENCES (date). Les lignes contenant la station sont rapproché par id origine.;INCOHERENT_DATA(id_station_source);NO_PARENT_ENTITY(id_station);Station 2;;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -;INCOHERENT_DATA(id_station_source);NO_PARENT_ENTITY(id_station);Station 2;;;invalide;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -Un UUID station invalide lève une erreur sur la station ET sur l’habitat;INVALID_UUID(unique_id_sinp_station);INVALID_UUID(unique_id_sinp_station),ERRONEOUS_PARENT_ENTITY;;Erroneous 1;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;6c02ef80-2e78-4c2c-b8b5-1c75e2349fc2;prairie;24; -Un UUID station invalide lève une erreur sur la station uniquement si pas d’habitat;INVALID_UUID(unique_id_sinp_station),MISSING_VALUE(date_min);Pas d’habitat;;Erroneous 2;;;17/11/2024;Toto;;POINT(3.634 44.399);;;;; -Un UUID station invalide lève une erreur sur l’habitat uniquement si pas de station. Comme pour un précédent test d’incohérence,, NO PARENT_ENTITY n’est pas levé en raison d’un choix d’implémentation qui peut être modifié.;Pas de station;INVALID_UUID(unique_id_sinp_station);;Erroneous 3;;;;Toto;;;;;prairie;24; -Les UUID ≠ mais les id origine sont identique !;INCOHERENT_DATA [UUID ≠];ERRONEOUS_PARENT_ENTITY;Station 3;dd0d12fc-bb85-4029-9c72-14fd8583f9bb;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -;INCOHERENT_DATA [UUID ≠];ERRONEOUS_PARENT_ENTITY;Station 3;330bb0f5-dc1c-431a-af1a-d70138b8c99d;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -Les UUID sont égaux mais les id origine ≠ !;INCOHERENT_DATA [id_station_source ≠];ERRONEOUS_PARENT_ENTITY;Station 4;a5c37acb-c966-4024-bea6-71ec125b51c8;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -;INCOHERENT_DATA [id_station_source ≠];ERRONEOUS_PARENT_ENTITY;Station 5;a5c37acb-c966-4024-bea6-71ec125b51c8;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -Les id origine sont identique, mais les UUID ne sont pas toujours renseignés.;INCOHERENT_DATA [UUID ≠];ERRONEOUS_PARENT_ENTITY;Station 6;7ed90696-4e74-4ed5-98a4-518eea009a7f;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -;INCOHERENT_DATA [UUID ≠];ERRONEOUS_PARENT_ENTITY;Station 6;;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -Les UUID sont égaux mais les id origine ne sont pas toujours renseignés.;INCOHERENT_DATA [id_station_source ≠];ERRONEOUS_PARENT_ENTITY;Station 7;c4262f95-0b19-422a-848b-8f83c292d27a;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -;INCOHERENT_DATA [id_station_source ≠];ERRONEOUS_PARENT_ENTITY;;c4262f95-0b19-422a-848b-8f83c292d27a;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -Il y a ni UUID, ni id_origine : l’UUID sera généré.;OK !;OK !;;;VALID_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -Import d’un habitat dans une station existante ailleurs dans le fichier, référencé par UUID.;Pas de station;OK !;;462d385f-489a-436b-babb-8cca5fc62e1d;;;;Toto;;;;;prairie;24; -Import d’un habitat dans une station existante ailleurs dans le fichier, référencé par id origine.;Pas de station;OK !;Station 1;;;;;Toto;;;;;prairie;24; -On importe une station qui existe déjà en base : elle est ignorée;SKIP_EXISTING_UUID;Pas d’habitat;;EXISTING_STATION_UUID;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;;; -On importe une station qui existe déjà en base et un nouvel habitat, seul l’habitat est importé;SKIP_EXISTING_UUID;OK !;;EXISTING_STATION_UUID;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24; -On importe une station et un habitat existant déjà en base;SKIP_EXISTING_UUID;SKIP_EXISTING_UUID;;EXISTING_STATION_UUID;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;EXISTING_HABITAT_UUID;prairie;24; +Objectif du test;Erreur station;Erreur habitat;id_station_source;unique_id_sinp_station;unique_dataset_id;date_min;date_max;observers;id_nomenclature_area_surface_calculation;WKT;id_nomenclature_geographic_object;unique_id_sinp_habitat;nom_cite;cd_hab;technical_precision;id_nomenclature_collection_technique +Station + habitat sur la même ligne;OK !;OK !;;afa81c29-c75d-408d-bf48-53cce02d5561;VALID_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;4ee53579-b09b-408f-aa1f-d62495a66667;prairie;24;; +Station uniquement;OK !;Pas d’habitat;;9d3fb1bd-6148-45c4-aa13-ff9212155afe;VALID_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;;;; +Habitat uniquement dans une station existante en base.;Pas de station;OK !;;EXISTING_STATION_UUID;;;;Toto;;;;05f0163a-ab14-4045-84b9-b513188092ae;prairie;24;; +Dataset innexistant, habitat valide mais pas le parent;DATASET_NOT_FOUND(unique_dataset_id), INCOHERENT_DATA;ERRONEOUS_PARENT_ENTITY;;bdc3346d-0fc3-40fa-b787-be927e4dd82e;050d613c-543f-47fd-800a-13931b2721c7;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;2ff4867d-6943-45d8-873d-187fbc6d67a7;prairie;24;; +Dataset interdit, habitat valide mais pas le parent;DATASET_NOT_AUTHORIZED(unique_dataset_id);ERRONEOUS_PARENT_ENTITY;;f5f031a3-cf1b-419c-9817-69c39f51aef4;FORBIDDEN_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;5dfb9930-4795-4e6f-baae-3dd86abb3b70;prairie;24;; +Dataset UUID invalide;INVALID_UUID(unique_dataset_id);Pas d’habitat;;;erroneous;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);;;;;; +Champs géométrique manquant;NO-GEOM(Champs géométriques);Pas d’habitat;;;;17/11/2023;17/11/2023;Toto;;;;;;;; +Champs requis manquant;MISSING_VALUE(date_min);ERRONEOUS_PARENT_ENTITY;;4ee7728d-387d-49c5-b9a3-4162b0987fa5;;;;Toto;;POINT(3.634 44.399);St;aeb10ac4-6d69-4fa6-8df6-14d9304911df;prairie;24;; +Habitat mais pas de station référencée;Pas de station;NO_PARENT_ENTITY(id_station);;;;;;Toto;;;;;prairie;24;; +Uniquement un uuid station, mais on ne sait pas s’il appartient à une station ou s’il sert à indiquer le parent d’un habitat;ORPHAN_ROW(unique_id_sinp_station);ORPHAN_ROW(unique_id_sinp_station);;258a2478-8a0e-4321-83df-c2313ad3040e;;;;Toto;;;;;;;; +Uniquement un id station source, mais on ne sait pas s’il appartient à une station ou s’il sert à indiquer le parent d’un habitat;ORPHAN_ROW(id_station_source);ORPHAN_ROW(id_station_source);Station -1;;;;;Toto;;;;;;;; +Uniquement UUID station + id station source, mais on ne sait pas s’ils appartiennent à une station ou s’ils servent à indiquer le parent d’un habitat;ORPHAN_ROW(unique_id_sinp_station, id_station_source);ORPHAN_ROW(unique_id_sinp_station,id_station_source);Station -2;54e54935-982b-4da3-9aaf-e87e49a1fdf1;;;;Toto;;;;;;;; +On importe 2 habitats dans une même nouvelle station dont les données sont répétées. Les lignes contenant la station sont rapproché par UUID.;OK !;OK !;;462d385f-489a-436b-babb-8cca5fc62e1d;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;e5e7a184-3e92-4adb-a721-5bd004b3397f;forêt;24;; +;OK !;OK !;;462d385f-489a-436b-babb-8cca5fc62e1d;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;8f52f122-b9ae-45b3-b947-2c9f7934b823;prairie;24;; +On importe 2 habitats dans une même nouvelle station dont les données sont répétées MAIS AVEC DES DIFFÉRENCES (date). Les lignes contenant la station sont rapproché par UUID.;INCOHERENT_DATA(unique_id_sinp_station);NO_PARENT_ENTITY(id_station);;74be5e79-72e7-42a8-ba2e-d5e27c9caddb;;17/11/2023;;Toto;;POINT(3.634 44.399);St;d91496e9-d904-45a8-9e18-cb8acbbb6ea6;prairie;24;; +;INCOHERENT_DATA(unique_id_sinp_station);NO_PARENT_ENTITY(id_station);;74be5e79-72e7-42a8-ba2e-d5e27c9caddb;;18/11/2023;;Toto;;POINT(3.634 44.399);St;;prairie;24;; +On importe 2 habitats dans une même nouvelle station dont les données sont répétées mais avec des différences (date INVALIDE). Les lignes contenant la station sont rapproché par UUID. On vérifie qu’on a pas d’erreur sur la date car les contrôles ne doivent pas être lancé si les données sont incohérentes. En revanche, les contrôles des habitats doivent bien être lancés.;INCOHERENT_DATA(unique_id_sinp_station);NO_PARENT_ENTITY(id_station);;74be5e79-72e7-42a8-ba2e-d5e27c9caddb;;17/11/2023;;Toto;;POINT(3.634 44.399);St;;prairie;24;; +NO_PARENT_ENTITY(id_station) non levé sur l’habitat en raison de l’implémentation du check qui ignore les lignes erronées. À voir s’il faut le faire évoluer.;INCOHERENT_DATA(unique_id_sinp_station);INVALID_INTEGER(cd_hab);;74be5e79-72e7-42a8-ba2e-d5e27c9caddb;;date invalide;;Toto;;POINT(3.634 44.399);St;;prairie;invalide;; +On importe 2 habitats dans une même nouvelle station dont les données sont répétées. Les lignes contenant la station sont rapproché par id origine.;OK !;OK !;Station 1;;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +;OK !;OK !;Station 1;;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +On importe 2 habitats dans une même nouvelle station dont les données sont répétées MAIS AVEC DES DIFFÉRENCES (date). Les lignes contenant la station sont rapproché par id origine.;INCOHERENT_DATA(id_station_source);NO_PARENT_ENTITY(id_station);Station 2;;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +;INCOHERENT_DATA(id_station_source);NO_PARENT_ENTITY(id_station);Station 2;;;invalide;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +Un UUID station invalide lève une erreur sur la station ET sur l’habitat;INVALID_UUID(unique_id_sinp_station);INVALID_UUID(unique_id_sinp_station),ERRONEOUS_PARENT_ENTITY;;Erroneous 1;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;6c02ef80-2e78-4c2c-b8b5-1c75e2349fc2;prairie;24;; +Un UUID station invalide lève une erreur sur la station uniquement si pas d’habitat;INVALID_UUID(unique_id_sinp_station),MISSING_VALUE(date_min);Pas d’habitat;;Erroneous 2;;;17/11/2024;Toto;;POINT(3.634 44.399);;;;;; +Un UUID station invalide lève une erreur sur l’habitat uniquement si pas de station. Comme pour un précédent test d’incohérence,, NO PARENT_ENTITY n’est pas levé en raison d’un choix d’implémentation qui peut être modifié.;Pas de station;INVALID_UUID(unique_id_sinp_station);;Erroneous 3;;;;Toto;;;;;prairie;24;; +Les UUID ≠ mais les id origine sont identique !;INCOHERENT_DATA [UUID ≠];ERRONEOUS_PARENT_ENTITY;Station 3;dd0d12fc-bb85-4029-9c72-14fd8583f9bb;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +;INCOHERENT_DATA [UUID ≠];ERRONEOUS_PARENT_ENTITY;Station 3;330bb0f5-dc1c-431a-af1a-d70138b8c99d;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +Les UUID sont égaux mais les id origine ≠ !;INCOHERENT_DATA [id_station_source ≠];ERRONEOUS_PARENT_ENTITY;Station 4;a5c37acb-c966-4024-bea6-71ec125b51c8;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +;INCOHERENT_DATA [id_station_source ≠];ERRONEOUS_PARENT_ENTITY;Station 5;a5c37acb-c966-4024-bea6-71ec125b51c8;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +Les id origine sont identique, mais les UUID ne sont pas toujours renseignés.;INCOHERENT_DATA [UUID ≠];ERRONEOUS_PARENT_ENTITY;Station 6;7ed90696-4e74-4ed5-98a4-518eea009a7f;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +;INCOHERENT_DATA [UUID ≠];ERRONEOUS_PARENT_ENTITY;Station 6;;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +Les UUID sont égaux mais les id origine ne sont pas toujours renseignés.;INCOHERENT_DATA [id_station_source ≠];ERRONEOUS_PARENT_ENTITY;Station 7;c4262f95-0b19-422a-848b-8f83c292d27a;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +;INCOHERENT_DATA [id_station_source ≠];ERRONEOUS_PARENT_ENTITY;;c4262f95-0b19-422a-848b-8f83c292d27a;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +Il y a ni UUID, ni id_origine : l’UUID sera généré.;OK !;OK !;;;VALID_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +Import d’un habitat dans une station existante ailleurs dans le fichier, référencé par UUID.;Pas de station;OK !;;462d385f-489a-436b-babb-8cca5fc62e1d;;;;Toto;;;;;prairie;24;; +Import d’un habitat dans une station existante ailleurs dans le fichier, référencé par id origine.;Pas de station;OK !;Station 1;;;;;Toto;;;;;prairie;24;; +On importe une station qui existe déjà en base : elle est ignorée;SKIP_EXISTING_UUID;Pas d’habitat;;EXISTING_STATION_UUID;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;;;; +On importe une station qui existe déjà en base et un nouvel habitat, seul l’habitat est importé;SKIP_EXISTING_UUID;OK !;;EXISTING_STATION_UUID;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;; +On importe une station et un habitat existant déjà en base;SKIP_EXISTING_UUID;SKIP_EXISTING_UUID;;EXISTING_STATION_UUID;;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;EXISTING_HABITAT_UUID;prairie;24;; +technique collect vaut « autre » mais pas de précision fournise;OK !;CONDITIONAL_MANDATORY_FIELD_ERROR;;;VALID_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;;10 +technique collect vaut « autre » et une précision est bien fournies;OK !;OK !;;;VALID_DATASET_UUID;17/11/2023;17/11/2023;Toto;;POINT(3.634 44.399);St;;prairie;24;moyen précis;10 diff --git a/backend/geonature/tests/imports/test_imports_occhab.py b/backend/geonature/tests/imports/test_imports_occhab.py index dbee7ac133..3f72eb2160 100644 --- a/backend/geonature/tests/imports/test_imports_occhab.py +++ b/backend/geonature/tests/imports/test_imports_occhab.py @@ -315,6 +315,12 @@ def test_import_valid_file(self, imported_import): "id_station", frozenset({10, 16, 17, 18, 22, 23, 27, 28, 29, 30, 31, 32, 33, 34}), # 19,26? ), + ( + ImportCodeError.CONDITIONAL_MANDATORY_FIELD_ERROR, + "habitat", + "id_nomenclature_collection_technique", + frozenset({41}), + ), ( ImportCodeError.SKIP_EXISTING_UUID, "habitat", @@ -336,7 +342,7 @@ def test_import_valid_file(self, imported_import): ), }, ) - assert imported_import.statistics == {"station_count": 5, "habitat_count": 10} + assert imported_import.statistics == {"station_count": 7, "habitat_count": 11} assert ( db.session.scalar( sa.select(sa.func.count()).where(Station.id_import == imported_import.id_import) diff --git a/contrib/gn_module_occhab/backend/gn_module_occhab/imports/actions.py b/contrib/gn_module_occhab/backend/gn_module_occhab/imports/actions.py index 2b8132eac9..6ad0e2854c 100644 --- a/contrib/gn_module_occhab/backend/gn_module_occhab/imports/actions.py +++ b/contrib/gn_module_occhab/backend/gn_module_occhab/imports/actions.py @@ -51,6 +51,7 @@ set_parent_line_no, init_rows_validity, check_orphan_rows, + check_nomenclature_technique_collect, ) from geonature.core.imports.checks.sql.core import ( check_mandatory_field, @@ -173,6 +174,13 @@ def check_habitat_sql(imprt): else: check_mandatory_field(imprt, entity_habitat, fields["unique_id_sinp_habitat"]) + check_nomenclature_technique_collect( + imprt, + entity_habitat, + fields["id_nomenclature_collection_technique"], + fields["technical_precision"], + ) + set_id_parent_from_destination( imprt, parent_entity=entity_station,