Skip to content

Commit

Permalink
make tests robust to extra data
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Jan 4, 2024
1 parent bbf94b3 commit a15c37a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 15 additions & 4 deletions backend/geonature/tests/test_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from jsonschema import validate as validate_json
from pypnusershub.tests.utils import logged_user_headers, set_logged_user
from ref_geo.models import BibAreasTypes, LAreas
from geonature.core.gn_synthese.utils.query_select_sqla import remove_accents

from shapely.geometry import Point
from sqlalchemy import func, select
Expand Down Expand Up @@ -386,17 +387,27 @@ def test_get_observations_for_web_filter_source_by_id_module(
assert len(response_data) == expected_length

@pytest.mark.parametrize(
"observer_input,expected_length_synthese",
[("Vincent", 1), ("Camillé", 2), ("Camille, Elie", 2), ("Jane Doe", 0)],
"observer_input,expect_observations",
[("Vincent", True), ("Camillé", True), ("Camille,Elie", True), ("Jane Doe", False)],
)
def test_get_observations_for_web_filter_observers(
self, users, synthese_for_observers, observer_input, expected_length_synthese
self, users, synthese_for_observers, observer_input, expect_observations
):
set_logged_user(self.client, users["admin_user"])

filters = {"observers": observer_input}
r = self.client.get(url_for("gn_synthese.get_observations_for_web"), json=filters)
assert len(r.json["features"]) == expected_length_synthese
if expect_observations:
for feature in r.json["features"]:
assert any(
[
remove_accents(observer).lower()
in remove_accents(feature["properties"]["observers"]).lower()
for observer in observer_input.split(",")
]
), feature["properties"]["observers"]
else:
assert r.json["features"] == []

def test_get_synthese_data_cruved(self, app, users, synthese_data, datasets):
set_logged_user(self.client, users["self_user"])
Expand Down
3 changes: 1 addition & 2 deletions backend/geonature/tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ def test_get_organismes_jdd(self, users, datasets):
set_logged_user(self.client, users["admin_user"])

response = self.client.get(url_for("users.get_organismes_jdd"))
for org in response.json:
print("EXPECTED", org["nom_organisme"])
assert users["admin_user"].organisme.nom_organisme in [
org["nom_organisme"] for org in response.json
]

@pytest.mark.xfail(reason="Quel est le but de ce test ?")
def test_get_organismes_jdd_no_dataset(self, users):
set_logged_user(self.client, users["admin_user"])

Expand Down

0 comments on commit a15c37a

Please sign in to comment.