Skip to content

Commit

Permalink
Order api with view_pk_column if not specify (#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
amandine-sahl authored Jun 5, 2023
1 parent d79d79e commit 0b9bd2a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions backend/gn_module_export/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ def get_one_export_api(id_export):
args.pop("token")
filters = {f: args.get(f) for f in args}

if not "orderby" in filters:
filters["orderby"] = export.view_pk_column

query = export.get_view_query(limit=limit, offset=offset, filters=filters)

data = query.return_query()
Expand Down
27 changes: 27 additions & 0 deletions backend/gn_module_export/tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,33 @@ def test_export_schema(self, exports, users):
assert response.status_code == 200
validate_json(instance=response.json, schema=schema)

def test_export_orderby(self, synthese_data, export_synthese_sinp, users):
set_logged_user_cookie(self.client, users["admin_user"])
response = self.client.get(
url_for(
"exports.get_one_export_api",
id_export=export_synthese_sinp.id,
)
)
assert response.status_code == 200

unordered_id_synthese = [i["id_synthese"] for i in response.json["items"]]
ordered_id_synthese = sorted(unordered_id_synthese)
assert ordered_id_synthese == unordered_id_synthese

unordered_cd_noms = [i["cd_nom"] for i in response.json["items"]]
ordered_cd_noms = sorted(unordered_cd_noms)
assert ordered_cd_noms != unordered_cd_noms
assert set(ordered_cd_noms).issubset(set(unordered_cd_noms))

response = self.client.get(
url_for(
"exports.get_one_export_api", id_export=export_synthese_sinp.id, orderby="cd_nom"
)
)
return_cd_noms = [i["cd_nom"] for i in response.json["items"]]
assert ordered_cd_noms == return_cd_noms

def test_unknown_export(self, exports, users):
set_logged_user_cookie(self.client, users["admin_user"])
response = self.client.get(url_for("exports.get_one_export_api", id_export=1000000))
Expand Down

0 comments on commit 0b9bd2a

Please sign in to comment.