40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import json
|
||
|
|
|
||
|
|
|
||
|
|
def test_repair_history_requires_auth(app_env):
|
||
|
|
client, _, _, _ = app_env
|
||
|
|
assert client.get("/api/system/repair-history").status_code == 401
|
||
|
|
|
||
|
|
|
||
|
|
def test_repair_history_returns_newest_valid_records(logged_in):
|
||
|
|
client, app, _, _, _ = logged_in
|
||
|
|
path = app.state.settings.data_dir / "repair.json"
|
||
|
|
records = [
|
||
|
|
{
|
||
|
|
"id": "first",
|
||
|
|
"date": "2026-09-14T08:01:00Z",
|
||
|
|
"status": "failed",
|
||
|
|
"problem": {"errors": ["api: unhealthy"], "console": "Traceback brut"},
|
||
|
|
"analysis_solution": "La clé ne pouvait pas être créée.",
|
||
|
|
"modifications": ["image reconstruite"],
|
||
|
|
},
|
||
|
|
{
|
||
|
|
"id": "second",
|
||
|
|
"date": "2026-09-14T09:01:00Z",
|
||
|
|
"status": "repaired",
|
||
|
|
"problem": {"errors": [], "console": ""},
|
||
|
|
"analysis_solution": "Tout est sain",
|
||
|
|
"modifications": ["services relancés"],
|
||
|
|
},
|
||
|
|
]
|
||
|
|
path.write_text(json.dumps(records), encoding="utf-8")
|
||
|
|
|
||
|
|
response = client.get("/api/system/repair-history")
|
||
|
|
|
||
|
|
assert response.status_code == 200
|
||
|
|
assert [item["id"] for item in response.json()] == ["second", "first"]
|
||
|
|
assert response.json()[0]["modifications"] == ["services relancés"]
|
||
|
|
assert response.json()[1]["problem"]["console"] == "Traceback brut"
|