@@ -50,3 +50,60 @@ def test_unsupported_sensor_returns_422(tmp_path: Path) -> None:
|
||||
)
|
||||
|
||||
assert response.status_code == 422
|
||||
|
||||
|
||||
def test_retrain_creates_and_replaces_persisted_model(tmp_path: Path) -> None:
|
||||
from app.ml.registry.model_registry import ModelRegistry
|
||||
|
||||
registry = ModelRegistry(tmp_path)
|
||||
with TestClient(app) as client:
|
||||
app.state.registry = registry
|
||||
created = client.post(
|
||||
"/ml/retrain",
|
||||
json={
|
||||
"modelId": "home-model",
|
||||
"samples": [
|
||||
{
|
||||
"sensor_id": "sensor.kitchen",
|
||||
"values": {"temperature": 21.0},
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
replaced = client.post(
|
||||
"/ml/retrain",
|
||||
json={
|
||||
"modelId": "home-model",
|
||||
"samples": [
|
||||
{
|
||||
"sensor_id": "sensor.bedroom",
|
||||
"values": {"temperature": 18.0},
|
||||
}
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
assert created.status_code == 200
|
||||
assert created.json() == {
|
||||
"model_id": "home-model",
|
||||
"supported_sensors": ["sensor.kitchen"],
|
||||
"replaced": False,
|
||||
}
|
||||
assert replaced.status_code == 200
|
||||
assert replaced.json() == {
|
||||
"model_id": "home-model",
|
||||
"supported_sensors": ["sensor.bedroom"],
|
||||
"replaced": True,
|
||||
}
|
||||
restarted = ModelRegistry(tmp_path)
|
||||
assert restarted.load_artifact("home-model").supported_sensors == ("sensor.bedroom",)
|
||||
|
||||
|
||||
def test_retrain_rejects_empty_samples() -> None:
|
||||
with TestClient(app) as client:
|
||||
response = client.post(
|
||||
"/ml/retrain",
|
||||
json={"modelId": "home-model", "samples": []},
|
||||
)
|
||||
|
||||
assert response.status_code == 422
|
||||
|
||||
Reference in New Issue
Block a user