gmao/tests/integration/test_phase16_navigation.py
root db46ec6374
Some checks are pending
CI - Tests et Syntax / lint-and-test (push) Waiting to run
fix(ui): expose legacy menu as parallel admin navigation
2026-08-23 09:38:23 +00:00

68 lines
2.5 KiB
Python

"""Couverture de la navigation métier introduite en phase 1.6."""
from app_new import db
from app_new.core.models.rbac import Role, UserRole
from app_new.core.models.user import User
def test_admin_sees_new_menu_and_legacy_reference(authenticated_client):
response = authenticated_client.get("/auth/profile")
assert response.status_code == 200
body = response.get_data(as_text=True)
for label in ("Mon travail", "Patrimoine", "Produits & stocks", "Documents", "Administration"):
assert label in body
assert "Ancien menu" in body
assert "Référentiel temporaire" in body or "temporaire" in body
assert body.index("Administration") < body.index("Ancien menu")
for group in ("Principal", "Interventions", "Équipements", "Configuration"):
assert group in body
def test_non_admin_does_not_see_admin_navigation(client, app):
with app.app_context():
role = Role.query.filter_by(slug="lecture", is_active=True).first()
user = User(username="phase16_lecture", email="phase16_lecture@gmao.local", full_name="Lecture phase 1.6", is_active=True)
user.set_password("phase16-lecture-password")
db.session.add(user)
db.session.flush()
db.session.add(UserRole(user_id=user.id, role_id=role.id))
db.session.commit()
user_id = user.id
try:
login = client.post("/auth/login", data={"username": "phase16_lecture", "password": "phase16-lecture-password"})
assert login.status_code == 302
response = client.get("/auth/profile")
assert response.status_code == 200
body = response.get_data(as_text=True)
assert "Administration" not in body
assert "Ancien menu" not in body
finally:
with app.app_context():
user = db.session.get(User, user_id)
if user:
db.session.delete(user)
db.session.commit()
def test_new_menu_destinations_do_not_return_accidental_404_or_500(authenticated_client):
paths = (
"/interventions/",
"/planning/rooms",
"/planning/",
"/equipments/",
"/equipments/buildings/",
"/equipments/zones/",
"/equipments/rooms/",
"/cleaning/products",
"/cleaning/references",
"/cleaning/stock",
"/companies/",
"/documents/",
"/documents/fds",
"/admin/users",
"/admin/roles",
"/admin/permissions",
)
for path in paths:
response = authenticated_client.get(path)
assert response.status_code not in (404, 500), path