Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl committed Dec 6, 2024
1 parent fbeed52 commit 361ca4e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions apptax/taxonomie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ def where_id_liste(cls, id_liste, *, query):
def where_params(cls, filters=None, *, query):

for filter in filters:
# Test empty values
if not filters[filter]:
continue

if hasattr(Taxref, filter) and isinstance(filters[filter], list):
col = getattr(Taxref, filter)
query = query.filter(col.in_(tuple(filters[filter])))
Expand Down
8 changes: 5 additions & 3 deletions apptax/taxonomie/routestaxref.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,13 @@ def get_taxref_list():
page = request.values.get("page", 1, int)
id_liste = None
cd_nom = None

if "id_liste" in request.values:
id_liste = request.values.get("id_liste").split(",")
id_liste = (
request.values.get("id_liste").split(",") if request.values.get("id_liste") else None
)
if "cd_nom" in request.values:
cd_nom = request.values.get("cd_nom").split(",")
cd_nom = request.values.get("cd_nom").split(",") if request.values.get("cd_nom") else None

fields = request.values.get("fields", type=str, default=[])
parameters = request.values.to_dict()
Expand All @@ -187,7 +190,6 @@ def get_taxref_list():

if id_liste and "-1" not in id_liste:
query = Taxref.where_id_liste(id_liste, query=query)

count_filter = db.session.scalar(
db.select(func.count()).select_from(
Taxref.where_params(parameters, query=query),
Expand Down
9 changes: 9 additions & 0 deletions apptax/tests/test_taxref.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,24 @@ def test_get_taxref_list(self, liste_with_names):

def test_get_taxref_list_filters_cd_noms(self):
# Test de la route taxref avec des filtres sur le cd_nom
# 1 cd_nom
response = self.client.get(
url_for("taxref.get_taxref_list"),
query_string={"cd_nom": 103536},
)
assert response.status_code == 200
assert len(response.json["items"]) == 1

# Plusieurs cd_nom
response = self.client.get(
url_for("taxref.get_taxref_list"),
query_string={"cd_nom": "103536, 461885,2891"},
)
assert len(response.json["items"]) == 3

# Valeur vide
response = self.client.get(
url_for("taxref.get_taxref_list"),
query_string={"cd_nom": ""},
)
assert response.status_code == 200

0 comments on commit 361ca4e

Please sign in to comment.