1+ import pytest
2+ from app import app
3+
4+
5+ @pytest .fixture
6+ def client ():
7+ app .config ["TESTING" ] = True
8+ with app .test_client () as c :
9+ yield c
10+
11+
12+ def test_root_ok_and_structure (client ):
13+ r = client .get ("/" )
14+ assert r .status_code == 200
15+
16+ data = r .get_json ()
17+ assert isinstance (data , dict )
18+
19+ # service
20+ assert "service" in data
21+ assert data ["service" ]["framework" ] == "Flask"
22+
23+ # system
24+ assert "system" in data
25+ assert "hostname" in data ["system" ]
26+ assert "python_version" in data ["system" ]
27+
28+ # runtime
29+ assert "runtime" in data
30+ assert "uptime_seconds" in data ["runtime" ]
31+ assert "current_time" in data ["runtime" ]
32+
33+ # endpoints
34+ assert "endpoints" in data
35+ assert isinstance (data ["endpoints" ], list )
36+
37+
38+ def test_health_ok_and_structure (client ):
39+ r = client .get ("/health" )
40+ assert r .status_code == 200
41+
42+ data = r .get_json ()
43+ assert isinstance (data , dict )
44+ assert data ["status" ] == "healthy"
45+ assert "timestamp" in data
46+ assert "uptime_seconds" in data
47+
48+
49+ def test_404_json (client ):
50+ r = client .get ("/nope" )
51+ assert r .status_code == 404
52+ data = r .get_json ()
53+ assert data ["error" ] == "Not Found"
0 commit comments