Impostazioni: durata loop, tolleranze, anagrafiche; tab Utenti con reset password (#47 #48 #49 #50 #51)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"""#50/#51: tab Utenti dentro Impostazioni, redirect da /admin/users, reset password."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.conftest import api_get_router
|
||||
|
||||
USER = {
|
||||
"id": 2, "username": "mario", "display_name": "Mario", "email": None,
|
||||
"roles": ["MeasurementTec"], "is_admin": False, "language_pref": "it",
|
||||
"theme_pref": "light", "active": True,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_admin_api():
|
||||
mock = MagicMock()
|
||||
mock.get.side_effect = api_get_router({
|
||||
"/api/users": [USER],
|
||||
"/api/settings": {"auto_logout_minutes": "30"},
|
||||
})
|
||||
with patch("blueprints.admin.api_client", mock):
|
||||
yield mock
|
||||
|
||||
|
||||
def test_users_url_redirects_to_settings_tab(logged_in_client, mock_admin_api):
|
||||
resp = logged_in_client.get("/admin/users")
|
||||
assert resp.status_code == 302
|
||||
assert resp.headers["Location"].endswith("/admin/settings?tab=utenti")
|
||||
|
||||
|
||||
def test_settings_has_users_tab_and_reset_for_admin(logged_in_client, mock_admin_api):
|
||||
resp = logged_in_client.get("/admin/settings?tab=utenti")
|
||||
assert resp.status_code == 200
|
||||
html = resp.data.decode("utf-8")
|
||||
assert "userManagement(" in html # pannello utenti incluso
|
||||
assert "openReset(user)" in html # pulsante reset password (#51)
|
||||
assert "mario" in html # utente caricato
|
||||
assert "tab: " in html and "utenti" in html # tab iniziale richiesta
|
||||
|
||||
|
||||
def test_navbar_has_no_users_link(logged_in_client, mock_admin_api):
|
||||
html = logged_in_client.get("/admin/settings").data.decode("utf-8")
|
||||
assert 'href="/admin/users"' not in html
|
||||
|
||||
|
||||
def test_non_admin_cannot_reach_users_tab(client, mock_admin_api):
|
||||
with client.session_transaction() as sess:
|
||||
sess["api_key"] = "k"
|
||||
sess["user"] = {"id": 3, "username": "op", "roles": ["MeasurementTec"],
|
||||
"is_admin": False, "language_pref": "it", "theme_pref": "light"}
|
||||
for url in ("/admin/settings?tab=utenti", "/admin/users"):
|
||||
resp = client.get(url)
|
||||
assert resp.status_code == 302
|
||||
assert "/admin/" not in resp.headers["Location"]
|
||||
mock_admin_api.get.assert_not_called()
|
||||
|
||||
|
||||
def test_password_reset_proxy(logged_in_client, mock_admin_api):
|
||||
mock_admin_api.put.return_value = {"message": "ok"}
|
||||
resp = logged_in_client.put("/admin/api/users/2/password", json={"password": "Nuova1234"})
|
||||
assert resp.status_code == 200
|
||||
mock_admin_api.put.assert_called_once_with(
|
||||
"/api/users/2/password", data={"password": "Nuova1234"})
|
||||
Reference in New Issue
Block a user