From 826fda5d674d3cec0c51247a45dbe269cbd280a4 Mon Sep 17 00:00:00 2001 From: Aicha ELOUADI Date: Thu, 11 Jun 2026 15:49:02 +0200 Subject: [PATCH 1/2] feat: description de la modification --- ressources/__pycache__/app.cpython-314.pyc | Bin 1673 -> 1673 bytes .../test_app.cpython-314-pytest-8.2.0.pyc | Bin 10552 -> 10552 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/ressources/__pycache__/app.cpython-314.pyc b/ressources/__pycache__/app.cpython-314.pyc index f546c65cb426e143af3648c6f0e47c29919819b1..741dec8d7cdcd640876a5a82b2854ce3289a1d83 100644 GIT binary patch delta 22 bcmeC=?d0Xv=HumJ0D|~(t*p%(d284JFr@_N delta 22 bcmeC=?d0Xv=HumJ00O=M#jJvjyfth9D+UB3 diff --git a/ressources/__pycache__/test_app.cpython-314-pytest-8.2.0.pyc b/ressources/__pycache__/test_app.cpython-314-pytest-8.2.0.pyc index 504307a2d5ea836c95a7ec44076cd8011fb7e6d6..dbd61c7f5d9fe580e27370eb04399ead97ac323f 100644 GIT binary patch delta 20 acmdlHv?GXHn~#@^0SHQGDsAM})dT=G;RLb( delta 20 acmdlHv?GXHn~#@^0SNd46gP6~Y61W Date: Thu, 11 Jun 2026 16:45:54 +0200 Subject: [PATCH 2/2] modification fichier appy et test --- ressources/app.py | 9 +++++++++ ressources/test_app.py | 25 ++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/ressources/app.py b/ressources/app.py index 60476c3..392720a 100644 --- a/ressources/app.py +++ b/ressources/app.py @@ -38,6 +38,15 @@ def logs_critical(): return jsonify({"critical_count": seuil, "alerte": alerte}) +@app.route("/logs/stats") +def logs_stats(): + total = sum(LOG_SUMMARY.values()) + return jsonify({ + "total": total, + "breakdown": LOG_SUMMARY + }) + + if __name__ == "__main__": app.run(debug=True, port=5001) # Ceci est une ligne volontairement beaucoup trop longue corrigé diff --git a/ressources/test_app.py b/ressources/test_app.py index ce56a43..7b9348c 100644 --- a/ressources/test_app.py +++ b/ressources/test_app.py @@ -5,6 +5,7 @@ import pytest from app import app +from flask.testing import FlaskClient @pytest.fixture @@ -13,7 +14,7 @@ def client(): return app.test_client() -def test_index_status(client): +def test_index_status(client: FlaskClient): """La route / retourne 200 avec le statut ok.""" response = client.get("/") assert response.status_code == 200 @@ -22,14 +23,14 @@ def test_index_status(client): assert data["service"] == "NexaCloud API" -def test_health(client): +def test_health(client: FlaskClient): """La route /health retourne healthy.""" response = client.get("/health") assert response.status_code == 200 assert response.get_json()["status"] == "healthy" -def test_logs_summary_structure(client): +def test_logs_summary_structure(client: FlaskClient): """Le résumé de logs contient les 4 niveaux attendus.""" response = client.get("/logs/summary") assert response.status_code == 200 @@ -39,7 +40,7 @@ def test_logs_summary_structure(client): assert isinstance(data[niveau], int) -def test_logs_summary_values(client): +def test_logs_summary_values(client: FlaskClient): """Les compteurs de logs ont les valeurs attendues.""" response = client.get("/logs/summary") data = response.get_json() @@ -49,7 +50,7 @@ def test_logs_summary_values(client): assert data["critical"] == 3 -def test_logs_critical_alerte(client): +def test_logs_critical_alerte(client: FlaskClient): """L'alerte est active quand il y a des critiques.""" response = client.get("/logs/critical") assert response.status_code == 200 @@ -57,3 +58,17 @@ def test_logs_critical_alerte(client): assert "critical_count" in data assert "alerte" in data assert data["alerte"] is True + + +def test_logs_stats(client: FlaskClient): + """La route /logs/stats retourne le total et le détail.""" + response = client.get("/logs/stats") + assert response.status_code == 200 + data = response.get_json() + assert "total" in data + assert "breakdown" in data + assert data["total"] == 185 + assert data["breakdown"]["info"] == 142 + assert data["breakdown"]["warning"] == 28 + assert data["breakdown"]["error"] == 12 + assert data["breakdown"]["critical"] == 3