from fastapi.testclient import TestClient import sys import os sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) from src.api import app client = TestClient(app) def test_health_check(): response = client.get("/health") assert response.status_code == 200 assert response.json() == {"status": "healthy"} def test_predict_valid_data(): # 41 features for NSL-KDD features = [0.0] * 41 response = client.post("/predict", json={"features": features}) assert response.status_code == 200 data = response.json() assert "is_anomaly" in data assert "anomaly_score" in data assert "status" in data def test_predict_invalid_data(): # Only 10 features, should fail features = [0.0] * 10 response = client.post("/predict", json={"features": features}) assert response.status_code == 200 # Returns 200 with error message in current implementation assert "error" in response.json()