Skip to content

Commit

Permalink
use set_logged_user_jwt in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Sep 13, 2023
1 parent 260e944 commit e42f756
Show file tree
Hide file tree
Showing 13 changed files with 181 additions and 174 deletions.
2 changes: 1 addition & 1 deletion backend/dependencies/Utils-Flask-SQLAlchemy
22 changes: 11 additions & 11 deletions backend/geonature/tests/test_gn_commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from geonature.utils.errors import GeoNatureError

from .fixtures import *
from .utils import set_logged_user_cookie
from .utils import set_logged_user_jwt


@pytest.fixture(scope="function")
Expand Down Expand Up @@ -321,20 +321,20 @@ def test_list_modules(self, users):
response = self.client.get(url_for("gn_commons.list_modules", exclude="GEONATURE"))
assert response.status_code == Unauthorized.code

set_logged_user_cookie(self.client, users["noright_user"])
set_logged_user_jwt(self.client, users["noright_user"])
response = self.client.get(url_for("gn_commons.list_modules", exclude="GEONATURE"))
assert response.status_code == 200
assert len(response.json) == 0

set_logged_user_cookie(self.client, users["admin_user"])
set_logged_user_jwt(self.client, users["admin_user"])
response = self.client.get(url_for("gn_commons.list_modules", exclude="GEONATURE"))
assert response.status_code == 200
assert len(response.json) > 0

def test_list_module_exclude(self, users):
excluded_module = "GEONATURE"

set_logged_user_cookie(self.client, users["admin_user"])
set_logged_user_jwt(self.client, users["admin_user"])

response = self.client.get(
url_for("gn_commons.list_modules"), query_string={"exclude": [excluded_module]}
Expand Down Expand Up @@ -370,12 +370,12 @@ def test_list_places(self, place, users):
response = self.client.get(url_for("gn_commons.list_places"))
assert response.status_code == Unauthorized.code

set_logged_user_cookie(self.client, users["user"])
set_logged_user_jwt(self.client, users["user"])
response = self.client.get(url_for("gn_commons.list_places"))
assert response.status_code == 200
assert place.id_place in [p["properties"]["id_place"] for p in response.json]

set_logged_user_cookie(self.client, users["associate_user"])
set_logged_user_jwt(self.client, users["associate_user"])
response = self.client.get(url_for("gn_commons.list_places"))
assert response.status_code == 200
assert place.id_place not in [p["properties"]["id_place"] for p in response.json]
Expand All @@ -390,7 +390,7 @@ def test_add_place(self, users):
response = self.client.post(url_for("gn_commons.add_place"))
assert response.status_code == Unauthorized.code

set_logged_user_cookie(self.client, users["user"])
set_logged_user_jwt(self.client, users["user"])
response = self.client.post(url_for("gn_commons.add_place"), data=geofeature)
assert response.status_code == 200
assert db.session.query(
Expand All @@ -399,7 +399,7 @@ def test_add_place(self, users):
).exists()
).scalar()

set_logged_user_cookie(self.client, users["user"])
set_logged_user_jwt(self.client, users["user"])
response = self.client.post(url_for("gn_commons.add_place"), data=geofeature)
assert response.status_code == Conflict.code

Expand All @@ -408,14 +408,14 @@ def test_delete_place(self, place, users):
response = self.client.delete(url_for("gn_commons.delete_place", id_place=unexisting_id))
assert response.status_code == Unauthorized.code

set_logged_user_cookie(self.client, users["associate_user"])
set_logged_user_jwt(self.client, users["associate_user"])
response = self.client.delete(url_for("gn_commons.delete_place", id_place=unexisting_id))
assert response.status_code == NotFound.code

response = self.client.delete(url_for("gn_commons.delete_place", id_place=place.id_place))
assert response.status_code == Forbidden.code

set_logged_user_cookie(self.client, users["user"])
set_logged_user_jwt(self.client, users["user"])
response = self.client.delete(url_for("gn_commons.delete_place", id_place=place.id_place))
assert response.status_code == 204
assert not db.session.query(
Expand Down Expand Up @@ -463,7 +463,7 @@ def test_get_additional_fields_not_exist_in_module(self):
assert len(data) == 0

def test_additional_field_admin(self, app, users, module, perm_object):
set_logged_user_cookie(self.client, users["admin_user"])
set_logged_user_jwt(self.client, users["admin_user"])
app.config["ADDITIONAL_FIELDS"]["IMPLEMENTED_MODULES"] = [module.module_code]
app.config["ADDITIONAL_FIELDS"]["IMPLEMENTED_OBJECTS"] = [perm_object.code_object]
form_values = {
Expand Down
Loading

0 comments on commit e42f756

Please sign in to comment.