The list query and the batch Ofsted fetch each picked 'the latest row' of fact_ofsted_inspection themselves, and _ofsted_block carried an older ungraded grade forward when the latest graded inspection gave none. All three now read marts.fact_ofsted_latest. List rows: ofsted_grade is the grade still in force, ofsted_grade_date when it was awarded or confirmed, ofsted_date the latest visit. The ofsted block gains current_grade and latest_visit and loses grade_source; overall_effectiveness is the graded inspection's own result. A school with only an inspection stays publishable in the sitemap. Requires fact_ofsted_latest (PR #183's pipeline run) on the database. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
"""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"})
|