Files
WebApi/tests/test_governance.py
T
alberto 82f7a18a9f F1a: user fixes
Keep the TrainingSource union named in OpenAPI and serialize the selected variant directly into the flat job config. Keep the inputs GET for file-type metadata and upload availability, and remove the listing and its description. Cover both job payloads, reject site-only extraneous fields, and verify upload validation.
2026-12-01 11:32:48 -06:00

37 lines
1.4 KiB
Python

from io import BytesIO
import pytest
from fastapi import HTTPException, UploadFile
from core.domains import Domain
from webapi.models import training_inputs, upload_training_inputs
def test_training_inputs(tmp_path, monkeypatch):
root = tmp_path / "reference"
monkeypatch.setenv("TEA_REFERENCE_ROOT", str(root))
assert training_inputs(Domain.TEA, "curve_x") == {"allowed": ["*.edf", "edades.csv"]}
with pytest.raises(HTTPException) as undefined:
training_inputs(Domain.TEA, "ados2_association")
assert undefined.value.status_code == 404
def upload(name, files):
return upload_training_inputs(
Domain.TEA,
"curve_x",
name,
[UploadFile(BytesIO(content), filename=filename) for filename, content in files],
)
expected = {"name": "cohort", "edf_files": 1, "has_ages": True, "bytes": 7}
assert upload("cohort", [("one.EDF", b"edf"), ("edades.csv", b"ages")]) == expected
for invalid in ("bad.txt", "../x"):
with pytest.raises(HTTPException) as rejected:
upload("cohort", [("two.edf", b"edf"), (invalid, b"bad")])
assert rejected.value.status_code == 422
with pytest.raises(HTTPException) as rejected:
upload("bad set", [("one.edf", b"edf")])
assert rejected.value.status_code == 422
assert {path.name for path in (root / "cohort").iterdir()} == {"one.EDF", "edades.csv"}