Repository navigation
Expand file tree
/
Copy pathtest_api.py
More file actions
49 lines (42 loc) · 1.83 KB
/
Copy pathtest_api.py
File metadata and controls
49 lines (42 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import unittest
from fastapi.testclient import TestClient
from src.api.app import app
class TestFastAPIGateway(unittest.TestCase):
def setUp(self):
self.client = TestClient(app)
def test_health_check(self):
response = self.client.get("/health")
self.assertEqual(response.status_code, 200)
data = response.json()
self.assertEqual(data["status"], "HEALTHY")
self.assertEqual(data["system"], "SentinelZone-AI")
def test_publish_edge_incident(self):
incident_packet = {
"event_id": "INC-TEST-001",
"timestamp": 1725642000.0,
"severity": "CRITICAL_LEVEL_3",
"min_ttc": 1.25,
"p_col": 0.89,
"agents": ["Worker #101", "Wheel Loader 02"]
}
response = self.client.post("/api/v1/incidents/publish", json=incident_packet)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["status"], "BROADCAST_SUCCESS")
self.assertEqual(response.json()["received_event"], "INC-TEST-001")
def test_submit_adjudication(self):
payload = {
"event_id": "INC-TEST-001",
"verdict": "TRUE_POSITIVE",
"confidence": 0.97,
"spotter_verified": False,
"worker_awareness_observed": False,
"root_cause_summary": "Uncontrolled machine reversing in worker pathway.",
"retraining_priority": "HIGH",
"recommended_mitigation": "Install physical demarcation line."
}
response = self.client.post("/api/v1/adjudication/submit", json=payload)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["status"], "ADJUDICATION_STORED")
self.assertEqual(response.json()["event_id"], "INC-TEST-001")
if __name__ == "__main__":
unittest.main()