fix(backend): serve the current Ofsted status from fact_ofsted_latest
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>
This commit is contained in:
1 parent
96732c56d1
commit
a9e3a6a700
8 files changed
+188
-78
No files matched your search
@@ -10,7 +10,10 @@ from backend.data_loader import _admissions_row_dict, _ofsted_block
|
||||
|
||||
def _row(**kw):
|
||||
base = dict(
|
||||
framework="RC", inspection_date=None, inspection_type=None,
|
||||
framework="RC", inspection_type=None,
|
||||
graded_inspection_date=None, ungraded_inspection_date=None, rc_inspection_date=None,
|
||||
latest_visit_date=None, latest_visit_kind=None, latest_visit_outcome=None,
|
||||
current_grade=None, current_grade_date=None, current_grade_basis=None,
|
||||
overall_effectiveness=None, quality_of_education=None,
|
||||
behaviour_attitudes=None, personal_development=None,
|
||||
leadership_management=None, early_years_provision=None,
|
||||
@@ -33,20 +36,41 @@ def test_report_card_block_and_provider_url():
|
||||
assert block["ofsted_page_url"] == "https://reports.ofsted.gov.uk/provider/21/100140"
|
||||
|
||||
|
||||
def test_grade_source_graded_vs_carried_forward():
|
||||
assert _ofsted_block(_row(overall_effectiveness=1), urn=1)["grade_source"] == "graded"
|
||||
carried = _ofsted_block(_row(ungraded_grade=2), urn=1)
|
||||
assert carried["grade_source"] == "ungraded_carried_forward"
|
||||
assert carried["overall_effectiveness"] == 2
|
||||
assert _ofsted_block(_row(), urn=1)["grade_source"] is None
|
||||
def test_no_grade_is_carried_past_a_newer_inspection():
|
||||
# Rabbsfarm (102408): the 2025 inspection gave no overall grade.
|
||||
block = _ofsted_block(_row(
|
||||
graded_inspection_date=date(2025, 6, 17), ungraded_inspection_date=date(2020, 2, 6),
|
||||
latest_visit_date=date(2025, 6, 17), latest_visit_kind="graded",
|
||||
ungraded_grade=2, ungraded_outcome="School remains Good", quality_of_education=3,
|
||||
), urn=102408)
|
||||
assert block["current_grade"] is None
|
||||
assert block["overall_effectiveness"] is None
|
||||
assert block["latest_visit"] == {"date": "2025-06-17", "kind": "graded", "outcome": None}
|
||||
assert block["inspection_date"] == "2025-06-17"
|
||||
assert "grade_source" not in block
|
||||
|
||||
|
||||
def test_confirmed_grade_is_dated_by_the_confirming_visit():
|
||||
block = _ofsted_block(_row(
|
||||
graded_inspection_date=date(2020, 1, 7), ungraded_inspection_date=date(2024, 7, 18),
|
||||
latest_visit_date=date(2024, 7, 18), latest_visit_kind="ungraded",
|
||||
latest_visit_outcome="School remains Good", overall_effectiveness=2,
|
||||
current_grade=2, current_grade_date=date(2024, 7, 18), current_grade_basis="confirmed",
|
||||
), urn=104762)
|
||||
assert block["current_grade"] == {"grade": 2, "date": "2024-07-18", "basis": "confirmed"}
|
||||
assert block["overall_effectiveness"] == 2
|
||||
assert block["inspection_date"] == "2020-01-07"
|
||||
|
||||
|
||||
def test_overall_sentinel_is_not_served_as_a_grade():
|
||||
assert _ofsted_block(_row(overall_effectiveness=9), urn=1)["overall_effectiveness"] is None
|
||||
|
||||
|
||||
def test_ofsted_block_carries_rc_inspection_date():
|
||||
o = _row(
|
||||
ungraded_grade=2,
|
||||
rc_achievement=1,
|
||||
rc_inspection_date=date(2026, 2, 3),
|
||||
inspection_date=date(2021, 10, 7),
|
||||
graded_inspection_date=date(2021, 10, 7),
|
||||
)
|
||||
block = _ofsted_block(o, urn=138690)
|
||||
assert block["rc_inspection_date"] == "2026-02-03"
|
||||
@@ -55,7 +79,7 @@ def test_ofsted_block_carries_rc_inspection_date():
|
||||
|
||||
|
||||
def test_ofsted_block_rc_inspection_date_none_when_absent():
|
||||
o = _row(overall_effectiveness=1, inspection_date=date(2021, 10, 13))
|
||||
o = _row(overall_effectiveness=1, graded_inspection_date=date(2021, 10, 13))
|
||||
block = _ofsted_block(o, urn=136276)
|
||||
assert block["rc_inspection_date"] is None
|
||||
|
||||
@@ -63,6 +87,7 @@ def test_ofsted_block_rc_inspection_date_none_when_absent():
|
||||
def test_ofsted_block_keeps_existing_keys():
|
||||
block = _ofsted_block(_row(overall_effectiveness=2, quality_of_education=2), urn=1)
|
||||
for key in ("framework", "inspection_date", "overall_effectiveness",
|
||||
"current_grade", "latest_visit",
|
||||
"quality_of_education", "rc_inclusion", "report_url"):
|
||||
assert key in block
|
||||
|
||||
|
||||
Reference in new issue
Block a user