From c11e75a460e4116fc51bbcac314cbedb5b9bcfc2 Mon Sep 17 00:00:00 2001 From: Etienne Delclaux Date: Tue, 8 Oct 2024 10:40:54 +0200 Subject: [PATCH] feat: complete users parameters in fixtures --- backend/geonature/tests/fixtures.py | 13 ++++--- backend/geonature/tests/test_synthese.py | 46 +++++++++++++----------- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/backend/geonature/tests/fixtures.py b/backend/geonature/tests/fixtures.py index 23b0e9a5da..fb0000a0ee 100644 --- a/backend/geonature/tests/fixtures.py +++ b/backend/geonature/tests/fixtures.py @@ -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), {}), ( ( @@ -513,6 +513,7 @@ def create_synthese( source, uuid=func.uuid_generate_v4(), cor_observers=[], + observers=[], date_min="", date_max="", altitude_min=800, @@ -541,6 +542,7 @@ def create_synthese( altitude_min=altitude_min, altitude_max=altitude_max, cor_observers=cor_observers, + observers=observers, **kwargs, ) @@ -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, diff --git a/backend/geonature/tests/test_synthese.py b/backend/geonature/tests/test_synthese.py index 7bc5d26219..1b2d9aa78b 100644 --- a/backend/geonature/tests/test_synthese.py +++ b/backend/geonature/tests/test_synthese.py @@ -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" @@ -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( @@ -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", @@ -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", @@ -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", @@ -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",