Skip to content

Commit

Permalink
Fix taxref route : noms with 2 lists - fix : PnX-SI/gn_mobile_occtax#263
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Sep 13, 2024
1 parent 14614a7 commit f118b30
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion apptax/taxonomie/routestaxref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
11 changes: 11 additions & 0 deletions apptax/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
13 changes: 12 additions & 1 deletion apptax/tests/test_taxref.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f118b30

Please sign in to comment.