from __future__ import annotations from fastapi.testclient import TestClient from app.main import app def test_ml_routes_are_exposed_by_production_app() -> None: with TestClient(app) as client: health = client.get("/ml/health") models = client.get("/ml/models") assert health.status_code == 200 assert models.status_code == 200 assert models.json() == {"models": []} def test_unknown_model_returns_404() -> None: with TestClient(app) as client: response = client.post( "/ml/predict", json={ "modelId": "missing", "sensor_id": "sensor.kitchen", "values": {"temperature": 21.0}, }, ) assert response.status_code == 404 def test_unsupported_sensor_returns_422(tmp_path) -> None: from app.ml.registry.model_registry import ModelRegistry from app.ml.training import TrainedArtifact registry = ModelRegistry(tmp_path) registry.register(TrainedArtifact("default", ("sensor.kitchen",))) with TestClient(app) as client: app.state.registry = registry response = client.post( "/ml/predict", json={ "modelId": "default", "sensor_id": "sensor.unknown", "values": {"temperature": 21.0}, }, ) assert response.status_code == 422