55from geonature .tests .fixtures import *
66from .fixtures import *
77
8+
89@pytest .mark .usefixtures ("client_class" )
910class 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