Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified ressources/__pycache__/app.cpython-314.pyc
Binary file not shown.
Binary file modified ressources/__pycache__/test_app.cpython-314-pytest-8.2.0.pyc
Binary file not shown.
9 changes: 9 additions & 0 deletions ressources/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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é
25 changes: 20 additions & 5 deletions ressources/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pytest
from app import app
from flask.testing import FlaskClient


@pytest.fixture
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -49,11 +50,25 @@ 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
data = response.get_json()
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
Loading