44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""Tests for sitemap generation (spec 2026-08-20, workstream W1).
|
|||
|
|
|
||
|
|
The sitemap is built from the in-memory school DataFrame, so these inject a
|
||
|
|
small frame via monkeypatch rather than touching a database.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import numpy as np
|
||
|
|
import pandas as pd
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
|
||
|
|
def _schools_df() -> pd.DataFrame:
|
||
|
|
"""Two schools: one with results, one with neither results nor Ofsted."""
|
||
|
|
base = {
|
||
|
|
"local_authority": "Testshire",
|
||
|
|
"school_type": "Academy",
|
||
|
|
"phase": "Primary",
|
||
|
|
"year": 202425,
|
||
|
|
"ofsted_date": None,
|
||
|
|
}
|
||
|
|
return pd.DataFrame(
|
||
|
|
[
|
||
|
|
{**base, "urn": 100001, "school_name": "Alpha Primary",
|
||
|
|
"rwm_expected_pct": 62.0, "attainment_8_score": np.nan,
|
||
|
|
"ofsted_grade": 2.0},
|
||
|
|
{**base, "urn": 100002, "school_name": "Ghost Primary",
|
||
|
|
"rwm_expected_pct": np.nan, "attainment_8_score": np.nan,
|
||
|
|
"ofsted_grade": np.nan},
|
||
|
|
]
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@pytest.fixture()
|
||
|
|
def sitemap(monkeypatch) -> str:
|
||
|
|
from backend import app as app_module
|
||
|
|
|
||
|
|
monkeypatch.setattr(app_module, "load_school_data", _schools_df)
|
||
|
|
return app_module.build_sitemap()
|
||
|
|
|
||
|
|
|
||
|
|
def test_every_loc_uses_the_www_host(sitemap):
|
||
|
|
# The apex 301s to www. A <loc> that redirects burns a crawl per URL.
|
||
|
|
assert "https://www.schoolcompare.co.uk" in sitemap
|
||
|
|
assert "https://schoolcompare.co.uk" not in sitemap
|