Files
WebApi/tests/test_webapp.py
T

37 lines
1.6 KiB
Python

"""Phase 3 and 4 gate, the WebApp: every page loads from the new API. The platform runs as
in production (API, Dagster), loaded with the synthetic CaCu and CaMa hospitals (CaMa's
models trained, none promoted) and the messy site; Playwright drives the real pages against
it (WebApp/e2e)."""
import json
import os
import subprocess
from pathlib import Path
import pytest
from test_conectar import ok, run, wait_for
from conftest import put_concept_map
ROOT = Path(__file__).parents[2]
HOSPITAL = ROOT / "tests" / "fixtures" / "hospital"
PIPELINES = ROOT / "tests" / "fixtures" / "pipelines"
@pytest.mark.webapp
@pytest.mark.parametrize("platform", ["sqlite"], indirect=True) # pages read one API either way
def test_every_page_loads_from_the_api(api, platform, messy_site):
for domain in ("cacu", "cama"):
drawn = (PIPELINES / f"hospital_{domain}.json").read_text()
put_concept_map(api, f"hospital_{domain}")
ok(api.put(f"/ingest/pipelines/{domain}", json=json.loads(
drawn.replace("{hospital}", str(HOSPITAL))))) # fmt: skip
run(api, domain)
# A trained CaMa version, unpromoted: what the governance page shows and refuses.
wait_for(api, ok(api.post("/models/cama/train", json={"as_of": "2026-11-24"}))["run_id"])
put_concept_map(api, "messy_site")
ok(api.put("/ingest/pipelines/site", json=json.loads(messy_site.drawn)))
run(api, "site")
subprocess.run(["npx", "playwright", "test"], cwd=ROOT / "WebApp", check=True,
env={**os.environ, "API_URL": str(api.base_url).rstrip("/")}) # fmt: skip