Skip to content

Commit

Permalink
Correction route taxref orderby (PnX-SI#470)
Browse files Browse the repository at this point in the history
Correction bug paramètre orderby de la route /taxref + Ajout test
  • Loading branch information
amandine-sahl authored Nov 17, 2023
1 parent 4700773 commit 1f1a545
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions apptax/taxonomie/routestaxref.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def genericTaxrefList(inBibtaxon, parameters):

# Order by
if "orderby" in parameters:
if parameters["orderby"] in taxrefColumns:
orderCol = getattr(taxrefColumns, parameters["orderby"])
if getattr(Taxref, parameters["orderby"], None):
orderCol = getattr(Taxref, parameters["orderby"])
else:
orderCol = None
if "order" in parameters:
if "order" in parameters and orderCol:
if parameters["order"] == "desc":
orderCol = orderCol.desc()
q = q.order_by(orderCol)
Expand Down
15 changes: 15 additions & 0 deletions apptax/tests/test_taxref.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ def test_getTaxrefList_routes_limit_fields(self):
if data:
assert current_schema.is_valid(data["items"])

def test_getTaxrefList_routes_order_by(self):
query_string = {"limit": 10, "orderby": "cd_nom"}
response = self.client.get(url_for("taxref.getTaxrefList"), query_string=query_string)

assert response.status_code == 200
data = response.json

if data:
assert self.schema_names.is_valid(data["items"])

query_string = {"limit": 10, "orderby": "unkwnow_field", "order": "asc"}
response = self.client.get(url_for("taxref.getTaxrefList"), query_string=query_string)

assert response.status_code == 200

def test_getTaxrefList_routes_limit_filter_id_liste(self, noms_example):
query_string = {"id_liste": 100, "fields": "cd_nom"}
response = self.client.get(url_for("taxref.getTaxrefList"), query_string=query_string)
Expand Down

0 comments on commit 1f1a545

Please sign in to comment.