diff --git a/apptax/taxonomie/routestaxref.py b/apptax/taxonomie/routestaxref.py index 406ddc60..11bcc1b9 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 6eefe5b9..ff81b555 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 3341bc4e..581fc0f8 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