"""The search badge reads ofsted_grade, ofsted_grade_date and ofsted_date from list rows (nextjs-app/lib/utils.ts buildOfstedListBadge). A field the list never sends would leave the badge without its year, or worse, fall back to "Not yet inspected". The school page reads current_grade and latest_visit from the ofsted block (lib/ofstedStatus.ts).""" import numpy as np import pandas as pd import pytest from fastapi.testclient import TestClient from backend.schemas import SCHOOL_COLUMNS def test_list_columns_include_the_status_fields(): for field in ("ofsted_grade", "ofsted_grade_date", "ofsted_date", "ofsted_rc_date"): assert field in SCHOOL_COLUMNS def _df() -> pd.DataFrame: # Rabbsfarm (102408): latest inspection 17 June 2025 gave no overall grade. return pd.DataFrame([{ "urn": 102408, "school_name": "Rabbsfarm Primary School", "phase": "Primary", "school_type": "Community school", "local_authority": "Hillingdon", "address": "Gordon Road, Yiewsley, UB7 8AH", "postcode": "UB7 8AH", "latitude": 51.51, "longitude": -0.47, "year": 202425, "rwm_expected_pct": 58.0, "total_pupils": 60, "gias_total_pupils": 616, "ofsted_grade": np.nan, "ofsted_grade_date": None, "ofsted_date": "2025-06-17", "ofsted_framework": "Schools - S5", "ofsted_rc_date": None, }]) @pytest.fixture() def client(monkeypatch): from backend import app as app_module monkeypatch.setattr(app_module, "load_school_data", _df) monkeypatch.setattr(app_module, "load_latest_school_data", _df) monkeypatch.setattr(app_module, "_place_registry", None) return TestClient(app_module.app, raise_server_exceptions=False) def test_search_rows_carry_the_status_fields(client): resp = client.get("/api/schools") assert resp.status_code == 200, resp.text row = resp.json()["schools"][0] assert row["ofsted_grade"] is None assert row["ofsted_date"] == "2025-06-17" assert "ofsted_grade_date" in row def test_a_school_with_only_an_inspection_is_publishable(): from backend.app import _has_publishable_data assert _has_publishable_data({"rwm_expected_pct": None, "attainment_8_score": None, "ofsted_grade": None, "ofsted_date": "2025-06-17"})