68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
"""Unit tier: the SSR rendering layer (content.py + format.py) fed committed backend
|
|
fixtures via the hermetic `client` fixture (tests/conftest.py). Asserts the rendering
|
|
*contract* — pages render and carry the expected structure — not exact climate numbers
|
|
(those are the backend's responsibility). Ported from the old backend-coupled
|
|
test_content.py; refresh the fixtures with scripts/capture-fixtures.sh.
|
|
"""
|
|
import re
|
|
|
|
import pytest
|
|
|
|
B = "/thermograph" # matches THERMOGRAPH_BASE in tests/conftest.py
|
|
SLUG = "london-england-gb"
|
|
MONTH = "july"
|
|
|
|
|
|
def test_robots_txt(client):
|
|
r = client.get(f"{B}/robots.txt")
|
|
assert r.status_code == 200
|
|
assert "Sitemap:" in r.text and "/sitemap.xml" in r.text
|
|
assert f"Disallow: {B}/api/" in r.text
|
|
|
|
|
|
def test_sitemap_lists_city_urls(client):
|
|
r = client.get(f"{B}/sitemap.xml")
|
|
assert r.status_code == 200
|
|
assert "<urlset" in r.text
|
|
assert f"/climate/{SLUG}</loc>" in r.text
|
|
assert f"/climate/{SLUG}/{MONTH}</loc>" in r.text
|
|
assert f"/climate/{SLUG}/records</loc>" in r.text
|
|
|
|
|
|
def test_city_page_renders_structure(client):
|
|
r = client.get(f"{B}/climate/{SLUG}")
|
|
assert r.status_code == 200
|
|
b = r.text
|
|
assert "London" in b and "climate" in b.lower()
|
|
assert 'rel="canonical"' in b and f"/climate/{SLUG}" in b
|
|
assert '"@type":"Dataset"' in b # JSON-LD dataset block
|
|
assert "average temperatures by month" in b.lower()
|
|
assert re.search(r"-?\d+°C</span>", b) # GB city -> Celsius
|
|
|
|
|
|
@pytest.mark.parametrize("path", ["", f"/{MONTH}", "/records"])
|
|
def test_city_subpages_render(client, path):
|
|
r = client.get(f"{B}/climate/{SLUG}{path}")
|
|
assert r.status_code == 200
|
|
assert "text/html" in r.headers["content-type"]
|
|
assert "__ORIGIN__" not in r.text # origin placeholder filled in
|
|
|
|
|
|
def test_homepage_renders(client):
|
|
r = client.get(f"{B}/")
|
|
assert r.status_code == 200
|
|
assert "text/html" in r.headers["content-type"]
|
|
|
|
|
|
def test_hub_renders(client):
|
|
r = client.get(f"{B}/climate")
|
|
assert r.status_code == 200
|
|
assert "text/html" in r.headers["content-type"]
|
|
|
|
|
|
def test_unknown_city_is_404(client):
|
|
assert client.get(f"{B}/climate/nope-not-a-city").status_code == 404
|
|
|
|
|
|
def test_unknown_month_is_404(client):
|
|
assert client.get(f"{B}/climate/{SLUG}/nonemonth").status_code == 404
|