Governance TEA EEG: reference cohorts, baselines export and import, cluster health, training and analysis jobs with progress, EDF upload, EEG queries
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""Cover progress lookup with a Flask client and temporary training and analysis folders.
|
||||
|
||||
Fails if the route selects the wrong directory or changes the progress response status or shape.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from flask import Flask
|
||||
|
||||
from webapi.blueprints.governance import governance_bp
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def progress_client(tmp_path, monkeypatch):
|
||||
"""Set up isolated job folders so reading the configured indicator root is required."""
|
||||
monkeypatch.setenv("INDICADORES_DIR", str(tmp_path))
|
||||
app = Flask(__name__)
|
||||
app.register_blueprint(governance_bp, url_prefix="/governance")
|
||||
return app.test_client()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("kind", "base"), [("train", "entrenamientos"), ("analyze", "analisis_eeg")])
|
||||
def test_progress_snapshot(progress_client, tmp_path, kind, base):
|
||||
"""Pin progress lookup for both job kinds. Fail if missing files succeed or the snapshot is wrapped."""
|
||||
url = f"/governance/tea/jobs/{kind}/example/progress"
|
||||
response = progress_client.get(url)
|
||||
assert response.status_code == 404 and set(response.json) == {"error"}
|
||||
|
||||
folder = tmp_path / base / "example"
|
||||
folder.mkdir(parents=True)
|
||||
(folder / "job.json").write_text("{}", encoding="utf-8")
|
||||
response = progress_client.get(url)
|
||||
assert response.status_code == 404 and set(response.json) == {"error"}
|
||||
|
||||
snapshot = {"updated_at": "2026-01-01T00:00:00+00:00", "phase": "midiendo", "done": 2, "total": 10,
|
||||
"elapsed_s": 1, "eta_s": None, "tasks": None, "cluster": None, "history": []}
|
||||
(folder / "progress.json").write_text(json.dumps(snapshot), encoding="utf-8")
|
||||
response = progress_client.get(url)
|
||||
assert response.status_code == 200
|
||||
assert response.json == snapshot
|
||||
|
||||
response = progress_client.get(f"/governance/tea/jobs/{kind}/nested%2F..%2Fexample/progress")
|
||||
assert response.status_code == 404 and set(response.json) == {"error"}
|
||||
|
||||
|
||||
def test_unknown_kind(progress_client):
|
||||
"""Pin invalid kind handling. Fail if an unsupported job kind becomes a missing job."""
|
||||
response = progress_client.get("/governance/tea/jobs/other/example/progress")
|
||||
assert response.status_code == 400
|
||||
assert set(response.json) == {"error"}
|
||||
Reference in New Issue
Block a user