From dde36d2b7f619494f8964f059de9267a0d5875af Mon Sep 17 00:00:00 2001 From: Etienne Delclaux Date: Tue, 8 Oct 2024 10:11:04 +0200 Subject: [PATCH] fix: taxon stats area_type parameter check --- backend/geonature/core/gn_synthese/routes.py | 5 ++++- backend/geonature/tests/test_synthese.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/geonature/core/gn_synthese/routes.py b/backend/geonature/core/gn_synthese/routes.py index d8b6a13f7c..255f9079f6 100644 --- a/backend/geonature/core/gn_synthese/routes.py +++ b/backend/geonature/core/gn_synthese/routes.py @@ -972,9 +972,12 @@ def taxon_stats(scope, cd_ref): area_type = request.args.get("area_type") - if not TaxonSheetUtils.is_valid_area_type(area_type): + if not area_type: raise BadRequest("Missing area_type parameter") + if not TaxonSheetUtils.is_valid_area_type(area_type): + raise BadRequest("Invalid area_type parameter") + areas_subquery = TaxonSheetUtils.get_area_subquery(area_type) taxref_cd_nom_list = TaxonSheetUtils.get_cd_nom_list_from_cd_ref(cd_ref) diff --git a/backend/geonature/tests/test_synthese.py b/backend/geonature/tests/test_synthese.py index e737bcd48b..7bc5d26219 100644 --- a/backend/geonature/tests/test_synthese.py +++ b/backend/geonature/tests/test_synthese.py @@ -1154,7 +1154,7 @@ def test_taxon_stats(self, synthese_data, users): url_for("gn_synthese.taxon_stats", cd_ref=CD_REF_VALID, area_type=AREA_TYPE_INVALID), ) assert response.status_code == 400 - assert response.json["description"] == "Invalid area_type" + assert response.json["description"] == "Invalid area_type parameter" # Invalid cd_ref parameter response = self.client.get(