Skip to content

Commit ebac962

Browse files
committed
Add 3 tests
1 parent fd5c6fd commit ebac962

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

backend/gn_module_zh/tests/fixtures.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import uuid
99

10+
1011
def create_zh(
1112
main_name,
1213
code,
@@ -21,6 +22,7 @@ def create_zh(
2122
):
2223
# Import here because TZH class need to be imported after "app instanced"
2324
from gn_module_zh.model.zh_schema import TZH
25+
2426
zh = TZH(
2527
main_name=main_name,
2628
code=code,
@@ -36,9 +38,10 @@ def create_zh(
3638
)
3739
return zh
3840

41+
3942
@pytest.fixture(scope="function")
4043
def zh_data(users):
41-
coords = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.))
44+
coords = ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0))
4245
polygon = Polygon(coords)
4346
date = datetime.datetime(2024, 10, 2, 11, 22, 33)
4447
id_sdage = 967
@@ -59,7 +62,7 @@ def zh_data(users):
5962
(
6063
"zh1",
6164
"05CEN0189",
62-
2, # id_org = 2 (not dynamic) because not same table bib_organismes used with the users
65+
2, # id_org = 2 (not dynamic) because not same table bib_organismes used with the users
6366
user.id_role,
6467
date,
6568
uuid.uuid4(),

backend/gn_module_zh/tests/test_bdd.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from geonature.tests.fixtures import *
66
from .fixtures import *
77

8+
89
@pytest.mark.usefixtures("client_class")
910
class TestBdd:
1011
def test_no_zh(self, users):
@@ -14,10 +15,37 @@ def test_no_zh(self, users):
1415
data = response.get_json()
1516
assert len(data["items"]["features"]) == 0
1617

17-
18-
def test_add_zh(self, users, zh_data):
18+
def test_get_zh(self, users, zh_data):
1919
set_logged_user(self.client, users["self_user"])
2020
response = self.client.get(url_for("pr_zh.get_zh"))
2121
assert response.status_code == 200
2222
data = response.get_json()
23-
assert len(data["items"]["features"]) > 0
23+
assert len(data["items"]["features"]) > 0
24+
25+
def test_get_zh_by_id(self, users, zh_data):
26+
set_logged_user(self.client, users["self_user"])
27+
response = self.client.get(url_for("pr_zh.get_zh_by_id", id_zh=zh_data.get("zh1").id_zh))
28+
assert response.status_code == 200
29+
data = response.get_json()
30+
assert data["properties"]["id_zh"] == zh_data.get("zh1").id_zh
31+
assert data["properties"]["main_name"] == zh_data.get("zh1").main_name
32+
33+
def test_get_zh_by_id_not_found(self, users):
34+
set_logged_user(self.client, users["self_user"])
35+
response = self.client.get(url_for("pr_zh.get_zh_by_id", id_zh=999999))
36+
# TODO: renvoie une 500 si la zone de protection n'existe pas ce serait préférable une 404
37+
assert response.status_code == 500
38+
# data = response.get_json()
39+
# print("data:", data)
40+
# assert data["message"] == "Zone de protection non trouvée"
41+
42+
def test_get_zh_by_id_no_auth(self, users, zh_data):
43+
set_logged_user(self.client, users["noright_user"])
44+
response = self.client.get(url_for("pr_zh.get_zh_by_id", id_zh=zh_data.get("zh1").id_zh))
45+
assert response.status_code == 403
46+
data = response.get_json()
47+
assert data["code"] == 403
48+
assert (
49+
data["description"]
50+
== f"User {users['noright_user'].get_id()} has no permissions to R in ZONES_HUMIDES"
51+
)

0 commit comments

Comments
 (0)