Skip to content

Commit

Permalink
feat: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Oct 7, 2024
1 parent 41ea982 commit ef5afb5
Showing 1 changed file with 75 additions and 11 deletions.
86 changes: 75 additions & 11 deletions backend/geonature/tests/test_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,40 +1226,100 @@ 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["stranger_user"])
set_logged_user(self.client, users["admin_user"])

SORT_ORDER_UNDEFINED = "sort-order-undefined"
SORT_ORDER_ASC = "asc"
SORT_ORDER_DESC = "desc"
PER_PAGE = 2
SORT_BY_UNDEFINED = "sort-by-undefined"

CD_REF = 2497
CD_REF_OBSERVERS = {
CD_REF_OBSERVERS_ASC = {
"items": [
{
"date_max": "Thu, 03 Oct 2024 08:09:10 GMT",
"date_max": "Mon, 20 May 2019 00:00:00 GMT",
"date_min": "Mon, 20 May 2019 00:00:00 GMT",
"media_count": 0,
"observation_count": 1,
"observer": "Albert Christophe",
},
{
"date_max": "Fri, 04 Oct 2024 17:04:09 GMT",
"date_min": "Wed, 02 Oct 2024 11:22:33 GMT",
"media_count": 0,
"observation_count": 4,
"observer": "Bob Bobby",
},
],
"total": 8,
"per_page": 2,
"page": 1,
}
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",
"media_count": 0,
"observation_count": 3,
"observer": "Bobby Bob",
}
"observer": "Rippert Laurent",
},
{
"date_max": "Sat, 20 Apr 2019 00:00:00 GMT",
"date_min": "Sat, 20 Apr 2019 00:00:00 GMT",
"media_count": 0,
"observation_count": 1,
"observer": "Lecuyer Clément",
},
],
"total": 2,
"per_page": 1,
"page": 1,
"per_page": 2,
"total": 8,
}

# Unknow sort_order parameters: shoudl fallback in asc
response = self.client.get(
url_for("gn_synthese.taxon_observers", cd_ref=CD_REF, sort_order=SORT_ORDER_UNDEFINED),
url_for(
"gn_synthese.taxon_observers",
cd_ref=CD_REF,
per_page=PER_PAGE,
sort_order=SORT_ORDER_UNDEFINED,
),
)
assert response.status_code == 200
assert response.get_json() == CD_REF_OBSERVERS_ASC

# Sort order ASC
response = self.client.get(
url_for(
"gn_synthese.taxon_observers",
cd_ref=CD_REF,
per_page=PER_PAGE,
sort_order=SORT_ORDER_ASC,
),
)
assert response.status_code == 200
assert response.get_json() == CD_REF_OBSERVERS_ASC

# Sort order DESC
response = self.client.get(
url_for(
"gn_synthese.taxon_observers",
cd_ref=CD_REF,
per_page=PER_PAGE,
sort_order=SORT_ORDER_DESC,
),
)
assert response.status_code == 200
assert response.get_json() == CD_REF_OBSERVERS_DESC

# Unknow sort_by parameters
response = self.client.get(
url_for(
"gn_synthese.taxon_observers",
cd_ref=CD_REF,
per_page=PER_PAGE,
sort_order=SORT_ORDER_ASC,
sort_by=SORT_BY_UNDEFINED,
),
Expand All @@ -1269,13 +1329,17 @@ def test_taxon_observer(self, synthese_data, users):
response.json["description"] == f"The sort_by column {SORT_BY_UNDEFINED} is not defined"
)

# Missing area_type parameter
# Everything is fine
response = self.client.get(
url_for("gn_synthese.taxon_observers", cd_ref=CD_REF),
url_for(
"gn_synthese.taxon_observers",
cd_ref=CD_REF,
per_page=PER_PAGE,
)
)

assert response.status_code == 200
assert response.get_json() == CD_REF_OBSERVERS
assert response.get_json() == CD_REF_OBSERVERS_ASC

def test_color_taxon(self, synthese_data, users):
# Note: require grids 5×5!
Expand Down

0 comments on commit ef5afb5

Please sign in to comment.