From a7f4dd014e8c6f1168bb88d62627947e70eeb893 Mon Sep 17 00:00:00 2001 From: Amandine Date: Thu, 26 Oct 2023 15:51:34 +0200 Subject: [PATCH] Feat/taxref group3 inpn (#447) * fix(db): add group3_inpn to taxref model * feat(api): specific route to get a list of group3 * Add group3 to taxon info * Test test_get_groupe3_inpn and format of taxrefDetail response * Changelog --------- Co-authored-by: Maxime Vergez --- apptax/taxonomie/models.py | 1 + apptax/taxonomie/routestaxref.py | 15 ++++++++++++ apptax/tests/test_taxref.py | 42 ++++++++++++++++++++++++++++++++ docs/changelog.md | 9 +++++++ 4 files changed, 67 insertions(+) diff --git a/apptax/taxonomie/models.py b/apptax/taxonomie/models.py index cd4fc26b..801b16d4 100644 --- a/apptax/taxonomie/models.py +++ b/apptax/taxonomie/models.py @@ -122,6 +122,7 @@ class Taxref(db.Model): nom_vern_eng = db.Column(db.Unicode) group1_inpn = db.Column(db.Unicode) group2_inpn = db.Column(db.Unicode) + group3_inpn = db.Column(db.Unicode) url = db.Column(db.Unicode) @hybrid_property diff --git a/apptax/taxonomie/routestaxref.py b/apptax/taxonomie/routestaxref.py index 95b503ee..b1ce1c66 100644 --- a/apptax/taxonomie/routestaxref.py +++ b/apptax/taxonomie/routestaxref.py @@ -160,6 +160,7 @@ def getTaxrefDetail(id): Taxref.nom_vern, Taxref.group1_inpn, Taxref.group2_inpn, + Taxref.group3_inpn, Taxref.id_rang, BibTaxrefRangs.nom_rang, BibTaxrefStatus.nom_statut, @@ -330,6 +331,20 @@ def get_regneGroup2Inpn_taxref(): return results +@adresses.route("/groupe3_inpn", methods=["GET"]) +@json_resp +def get_group3_inpn_taxref(): + """ + Retourne la liste des groupes 3 inpn + """ + data = ( + db.session.query(Taxref.group3_inpn) + .distinct(Taxref.group3_inpn) + .filter(Taxref.group3_inpn != None) + ).all() + return [d[0] for d in data] + + @adresses.route("/allnamebylist/", methods=["GET"]) @adresses.route("/allnamebylist", methods=["GET"]) @json_resp diff --git a/apptax/tests/test_taxref.py b/apptax/tests/test_taxref.py index 0e7c34da..c1a46e7b 100644 --- a/apptax/tests/test_taxref.py +++ b/apptax/tests/test_taxref.py @@ -24,6 +24,37 @@ class TestAPITaxref: ] ) + schema_taxref_detail = Schema( + { + "cd_nom": int, + "cd_ref": int, + "cd_sup": int, + "cd_taxsup": int, + "phylum": str, + "regne": str, + Optional("classe"): str, + "ordre": str, + "famille": str, + "group1_inpn": str, + "group2_inpn": str, + "group3_inpn": str, + "id_rang": str, + "nom_complet": str, + "nom_habitat": str, + "nom_rang": str, + "nom_statut": str, + "nom_valide": str, + "nom_vern": str, + "status": dict, + "synonymes": [ + { + "cd_nom": int, + "nom_complet": str, + } + ], + } + ) + def test_get_allnamebyListe_routes(self): query_string = {"limit": 10} response = self.client.get( @@ -103,6 +134,9 @@ def test_searchfield_routes(self): def test_taxrefDetail_routes(self): response = self.client.get(url_for("taxref.getTaxrefDetail", id=29708)) assert response.status_code == 200 + data = response.json + if data: + assert self.schema_taxref_detail.is_valid(data) def test_searchTaxref_routes(self): query_string = {"ilike-classe": "hex", "page": 1, "limit": 10} @@ -125,3 +159,11 @@ def test_taxrefversion_routes(self): response = self.client.get(url_for("taxref.getTaxrefVersion")) assert response.status_code == 200 assert json.loads(response.data)["version"] == 16 + + def test_get_groupe3_inpn(self): + response = self.client.get(url_for("taxref.get_group3_inpn_taxref")) + + assert response.status_code == 200 + response_json = response.json + assert "Coléoptères" in response_json + assert "Autres" in response_json diff --git a/docs/changelog.md b/docs/changelog.md index be4bddf4..e467d03a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,3 +1,12 @@ +1.13.1 (unrelease) +=================== + + +**🚀 Nouveautés** + +* Ajout de la colonne `group3_inpn` à la table taxref et à la réponse de la route `getTaxonDetail` (#447) +* Ajout d'une route listant les group3 `/groupe3_inpn` (#447) + 1.13.0 (2023-10-25) ===================