Skip to content

Commit

Permalink
feat: complete users parameters in fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Oct 17, 2024
1 parent ca6993b commit 8fe4062
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
3 changes: 0 additions & 3 deletions backend/geonature/core/gn_synthese/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,9 +1037,6 @@ def taxon_observers(scope, cd_ref):
sort_order = request.args.get("sort_order", SortOrder.ASC, SortOrder)

# Handle sorting
if sort_order not in [SortOrder.ASC, SortOrder.DESC]:
raise BadRequest(f"The sort_order {sort_order} is undefined")

if sort_by not in ["observer", "date_min", "date_max", "observation_count", "media_count"]:
raise BadRequest(f"The sort_by column {sort_by} is not defined")

Expand Down
7 changes: 2 additions & 5 deletions backend/geonature/core/gn_synthese/utils/taxon_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ class TaxonSheetUtils:
def update_query_with_sorting(query: Query, sort_by: str, sort_order: SortOrder) -> Query:
if sort_order == SortOrder.ASC:
return query.order_by(asc(sort_by))
elif sort_order == SortOrder.DESC:
return query.order_by(desc(sort_by))
else:
raise BadRequest("The sorting attribute is undefined")
return

return query.order_by(desc(sort_by))

@staticmethod
def paginate(query: Query, page: int, per_page: int) -> Pagination:
Expand Down
13 changes: 8 additions & 5 deletions backend/geonature/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ def create_user(
db.session.add(organisme)

users_to_create = [
(("noright_user", organisme, 0), {}),
(("stranger_user", None, 2), {}),
(("associate_user", organisme, 2), {}),
(("self_user", organisme, 1), {}),
(("noright_user", organisme, 0), {"nom_role": "User", "prenom_role": "NoRight"}),
(("stranger_user", None, 2), {"nom_role": "User", "prenom_role": "Stranger"}),
(("associate_user", organisme, 2), {"nom_role": "User", "prenom_role": "Associate"}),
(("self_user", organisme, 1), {"nom_role": "User", "prenom_role": "Self"}),
(("user", organisme, 2), {"nom_role": "Bob", "prenom_role": "Bobby"}),
(("admin_user", organisme, 3), {}),
(("admin_user", organisme, 3), {"nom_role": "Administrateur", "prenom_role": "Test"}),
(("associate_user_2_exclude_sensitive", organisme, 2, True), {}),
(
(
Expand Down Expand Up @@ -523,6 +523,7 @@ def create_synthese(
source,
uuid=func.uuid_generate_v4(),
cor_observers=[],
observers=[],
date_min="",
date_max="",
altitude_min=800,
Expand Down Expand Up @@ -551,6 +552,7 @@ def create_synthese(
altitude_min=altitude_min,
altitude_max=altitude_max,
cor_observers=cor_observers,
observers=observers,
**kwargs,
)

Expand Down Expand Up @@ -708,6 +710,7 @@ def synthese_data(app, users, datasets, source, sources_modules):
source_m,
unique_id_sinp,
[users["admin_user"], users["user"]],
["Administrative Test", "Bobby Bob"],
date_min,
date_max,
altitude_min,
Expand Down
46 changes: 25 additions & 21 deletions backend/geonature/tests/test_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,9 @@ def test_get_one_synthese_record(self, app, users, synthese_data):
assert response.status_code == Forbidden.code

def test_taxon_observer(self, synthese_data, users):
set_logged_user(self.client, users["admin_user"])
set_logged_user(self.client, users["stranger_user"])

## Test Data

SORT_ORDER_UNDEFINED = "sort-order-undefined"
SORT_ORDER_ASC = "asc"
Expand All @@ -1238,46 +1240,48 @@ def test_taxon_observer(self, synthese_data, users):
CD_REF_OBSERVERS_ASC = {
"items": [
{
"date_max": "Mon, 20 May 2019 00:00:00 GMT",
"date_min": "Mon, 20 May 2019 00:00:00 GMT",
"date_max": "Thu, 03 Oct 2024 08:09:10 GMT",
"date_min": "Wed, 02 Oct 2024 11:22:33 GMT",
"media_count": 0,
"observation_count": 1,
"observer": "Albert Christophe",
"observation_count": 3,
"observer": "Administrateur Test",
},
{
"date_max": "Fri, 04 Oct 2024 17:04:09 GMT",
"date_max": "Thu, 03 Oct 2024 08:09:10 GMT",
"date_min": "Wed, 02 Oct 2024 11:22:33 GMT",
"media_count": 0,
"observation_count": 4,
"observation_count": 3,
"observer": "Bob Bobby",
},
],
"total": 8,
"per_page": 2,
"page": 1,
"per_page": 2,
"total": 2,
}
CD_REF_OBSERVERS_DESC = {
"items": [
{
"date_max": "Sat, 20 Apr 2019 00:00:00 GMT",
"date_min": "Thu, 08 Sep 2016 00:00:00 GMT",
"date_max": "Thu, 03 Oct 2024 08:09:10 GMT",
"date_min": "Wed, 02 Oct 2024 11:22:33 GMT",
"media_count": 0,
"observation_count": 3,
"observer": "Rippert Laurent",
"observer": "Bob Bobby",
},
{
"date_max": "Sat, 20 Apr 2019 00:00:00 GMT",
"date_min": "Sat, 20 Apr 2019 00:00:00 GMT",
"date_max": "Thu, 03 Oct 2024 08:09:10 GMT",
"date_min": "Wed, 02 Oct 2024 11:22:33 GMT",
"media_count": 0,
"observation_count": 1,
"observer": "Lecuyer Clément",
"observation_count": 3,
"observer": "Administrateur Test",
},
],
"page": 1,
"per_page": 2,
"total": 8,
"total": 2,
}

## sort_order

# Unknow sort_order parameters: shoudl fallback in asc
response = self.client.get(
url_for(
Expand All @@ -1290,7 +1294,7 @@ def test_taxon_observer(self, synthese_data, users):
assert response.status_code == 200
assert response.get_json() == CD_REF_OBSERVERS_ASC

# Sort order ASC
# sort order ASC
response = self.client.get(
url_for(
"gn_synthese.taxon_observers",
Expand All @@ -1302,7 +1306,7 @@ def test_taxon_observer(self, synthese_data, users):
assert response.status_code == 200
assert response.get_json() == CD_REF_OBSERVERS_ASC

# Sort order DESC
# sort order DESC
response = self.client.get(
url_for(
"gn_synthese.taxon_observers",
Expand All @@ -1314,7 +1318,7 @@ def test_taxon_observer(self, synthese_data, users):
assert response.status_code == 200
assert response.get_json() == CD_REF_OBSERVERS_DESC

# Unknow sort_by parameters
## sort_by
response = self.client.get(
url_for(
"gn_synthese.taxon_observers",
Expand All @@ -1329,7 +1333,7 @@ def test_taxon_observer(self, synthese_data, users):
response.json["description"] == f"The sort_by column {SORT_BY_UNDEFINED} is not defined"
)

# Everything is fine
# Ok
response = self.client.get(
url_for(
"gn_synthese.taxon_observers",
Expand Down

0 comments on commit 8fe4062

Please sign in to comment.