test(dashboard): assert gauge_sites import route is reachable via real app

Guards against the router silently going unregistered again: builds the
actual dashboard app via create_app() and drives a real CSV import
through it end-to-end (POST + GET round-trip), instead of only hitting
the router in isolation.
This commit is contained in:
Matt Johnson 2026-07-16 22:48:57 +00:00
commit 5288089768

View file

@ -212,6 +212,42 @@ def test_ahps_detail_extracts_thresholds():
assert parsed["flood_major_ft"] == 14.5
# ============================================================================
# Item 3b -- gauge_sites import route is registered on the real app
#
# The endpoint logic above is fully covered, but until server.create_app()
# calls app.include_router(gauge_sites_import_router, ...) the route is
# unreachable in production -- the raw-router `client` fixture above can't
# catch that because it builds its own bare FastAPI app. This test drives
# the actual dashboard app the server process serves.
# ============================================================================
def test_gauge_sites_import_reachable_through_real_app():
from meshai.dashboard.server import create_app
app = create_app()
real_client = TestClient(app)
res = real_client.post(
"/api/gauge-sites/import",
json={
"format": "csv",
"data": "site_id,gauge_name,lat,lon\nUSGS-REAL1,Real App Creek,43.5,-114.5\n",
},
)
assert res.status_code == 200, res.text
body = res.json()
assert body["inserted"] == 1
assert body["updated"] == 0
# And it actually landed -- round-trip through the sibling curation
# router (also mounted on the real app) to prove the 200 reflects a
# real DB write through the real app, not a false positive.
listed = real_client.get("/api/gauge-sites").json()
assert any(r["site_id"] == "USGS-REAL1" for r in listed)
# ============================================================================
# Item 4 -- WFIGS tombstone column + reminder behavior
# ============================================================================