fix: API health check — correct TIGERweb CD field detection in admin test

Same bug as members.py: health check used old CD\d+FP$ regex (no match
for CD119) and skipped GEOID. Now mirrors members.py logic: GEOID primary,
STATE+CD\d+ fallback, Congressional layer filter.

Authored by: Jack Levy
This commit is contained in:
Jack Levy
2026-03-15 11:01:24 -04:00
parent bb10ff6dac
commit db0d841ef0

View File

@@ -473,9 +473,18 @@ def _test_rep_lookup() -> dict:
r2.raise_for_status()
results = r2.json().get("results", [])
for item in results:
if "Congressional" not in (item.get("layerName") or ""):
continue
attrs = item.get("attributes", {})
cd_field = next((k for k in attrs if _re.match(r"CD\d+FP$", k)), None)
if cd_field:
# Primary: GEOID = state FIPS (2) + district (2)
geoid = str(attrs.get("GEOID") or "").strip()
if len(geoid) == 4 and geoid.isdigit():
district = str(int(geoid[2:])) if geoid[2:].strip("0") else "At-large"
return {"status": "ok", "detail": f"Nominatim + TIGERweb reachable — district {district} found for ZIP 20001"}
# Fallback: STATE + CD{session} (e.g. STATE="06", CD119="30")
state_val = attrs.get("STATE")
cd_field = next((k for k in attrs if _re.match(r"CD\d+$", k)), None)
if state_val and cd_field:
district = str(int(str(attrs[cd_field]))) if str(attrs[cd_field]).strip("0") else "At-large"
return {"status": "ok", "detail": f"Nominatim + TIGERweb reachable — district {district} found for ZIP 20001"}
layers = [r.get("layerName") for r in results]