From f118b30c7f1a1074fb798ee01a76b328e7543381 Mon Sep 17 00:00:00 2001 From: amandine-sahl Date: Fri, 13 Sep 2024 10:02:10 +0200 Subject: [PATCH] Fix taxref route : noms with 2 lists - fix : https://github.com/PnX-SI/gn_mobile_occtax/issues/263 --- apptax/taxonomie/routestaxref.py | 4 +++- apptax/tests/fixtures.py | 11 +++++++++++ apptax/tests/test_taxref.py | 13 ++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/apptax/taxonomie/routestaxref.py b/apptax/taxonomie/routestaxref.py index 406ddc605..11bcc1b92 100644 --- a/apptax/taxonomie/routestaxref.py +++ b/apptax/taxonomie/routestaxref.py @@ -235,7 +235,9 @@ def getTaxrefHierarchieBibNoms(rang): def genericTaxrefList(inBibtaxon, parameters): - q = Taxref.query.options(raiseload("*"), joinedload(Taxref.bib_nom).joinedload(BibNoms.listes)) + q = Taxref.query.options( + raiseload("*"), joinedload(Taxref.bib_nom).joinedload(BibNoms.listes) + ).distinct() nbResultsWithoutFilter = q.count() diff --git a/apptax/tests/fixtures.py b/apptax/tests/fixtures.py index 6eefe5b9b..ff81b5552 100644 --- a/apptax/tests/fixtures.py +++ b/apptax/tests/fixtures.py @@ -56,6 +56,17 @@ def noms_example(attribut_example): liste.noms.append(nom) +@pytest.fixture +def nom_example_liste_2(noms_example): + with db.session.begin_nested(): + liste_2 = BibListes(code_liste="code_2", nom_liste="Liste 2", picto="picto") + db.session.add(liste_2) + noms = BibNoms.query.all() + for nom in noms: + liste_2.noms.append(nom) + return liste_2 + + @pytest.fixture def noms_without_listexample(): with db.session.begin_nested(): diff --git a/apptax/tests/test_taxref.py b/apptax/tests/test_taxref.py index 3341bc4e5..581fc0f83 100644 --- a/apptax/tests/test_taxref.py +++ b/apptax/tests/test_taxref.py @@ -4,7 +4,7 @@ from flask import url_for from schema import Schema, Optional, Or -from .fixtures import attribut_example, noms_example +from .fixtures import attribut_example, noms_example, nom_example_liste_2 @pytest.mark.usefixtures("client_class", "temporary_transaction") @@ -184,6 +184,17 @@ def test_getTaxrefList_routes_limit_filter_id_liste(self, noms_example): assert current_schema.is_valid(data["items"]) assert len(data["items"]) == 9 + def test_getTaxrefList_routes_limit_filter_2_id_liste(self, nom_example_liste_2): + liste_2 = nom_example_liste_2 + query_string = {"id_liste": f"100,{liste_2.id_liste}", "fields": "cd_nom", "limit": 2} + response = self.client.get(url_for("taxref.getTaxrefList"), query_string=query_string) + current_schema = Schema([{"cd_nom": int}]) + assert response.status_code == 200 + data = response.json + if data: + assert current_schema.is_valid(data["items"]) + assert len(data["items"]) == 2 + def test_get_distinct_routes(self): response = self.client.get(url_for("taxref.getDistinctField", field="regne")) assert response.status_code == 200