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 8, 2024
1 parent c8383e8 commit c11e75a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
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 @@ -513,6 +513,7 @@ def create_synthese(
source,
uuid=func.uuid_generate_v4(),
cor_observers=[],
observers=[],
date_min="",
date_max="",
altitude_min=800,
Expand Down Expand Up @@ -541,6 +542,7 @@ def create_synthese(
altitude_min=altitude_min,
altitude_max=altitude_max,
cor_observers=cor_observers,
observers=observers,
**kwargs,
)

Expand Down Expand Up @@ -698,6 +700,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 c11e75a

Please sign in to comment.