import sys import os from fastapi.testclient import TestClient # Ensure the local src layout is on PYTHONPATH for tests SRC_PATH = os.path.join(os.path.dirname(__file__), os.pardir, 'src') SYS_PATH = os.path.abspath(SRC_PATH) if SYS_PATH not in sys.path: sys.path.insert(0, SYS_PATH) from idea46_solarpulse_viz_real.main import app def test_health_endpoint(): client = TestClient(app) resp = client.get("/health") assert resp.status_code == 200 assert resp.json() == {"status": "ok"} def test_telemetry_endpoint_basic(): client = TestClient(app) payload = { "site_id": "site-A", "asset_id": "inverter-1", "timestamp": "2026-04-23T12:00:00Z", "v_current": 10.5, "temp": 34.2, "status": "OK", } resp = client.post("/telemetry", json=payload) assert resp.status_code == 200 data = resp.json() assert data["site_id"] == "site-A" assert "anomaly_score" in data