mirror of
https://github.com/kennethreitz/kennethreitz.org.git
synced 2026-07-22 01:19:30 +00:00
ea406a22f8
48 tests running in ~8s against an in-process client (api.requests), so broad refactors now have a safety net. The sweep test fetches every URL the sitemap advertises and names any that break. Fixes found while writing them: - Bare-slug legacy redirects failed for YYYY-MM-DD-named essays (the date-strip regex only handled the old YYYY-MM- format) - Search index was only built by background cache warming, so /api/search returned empty results until (or unless) warming finished; it now builds lazily on first use - Sitemap advertised /docs pages that no route serves; removed Also: make test target, pytest config in pyproject. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
29 lines
876 B
Python
29 lines
876 B
Python
"""Every URL the sitemap advertises must actually resolve.
|
|
|
|
This is the safety net for sweeping changes: if a refactor breaks any
|
|
page on the site, this test names it.
|
|
"""
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
SITE = "https://kennethreitz.org"
|
|
|
|
|
|
def test_every_sitemap_url_resolves(client):
|
|
r = client.get("/sitemap.xml")
|
|
assert r.status_code == 200
|
|
ns = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
|
locs = [el.text for el in ET.fromstring(r.text).findall(".//sm:loc", ns)]
|
|
paths = [loc.removeprefix(SITE) or "/" for loc in locs]
|
|
assert len(paths) > 200
|
|
|
|
failures = []
|
|
for path in paths:
|
|
resp = client.get(path)
|
|
if resp.status_code != 200:
|
|
failures.append(f"{path} -> {resp.status_code}")
|
|
|
|
assert not failures, (
|
|
f"{len(failures)}/{len(paths)} sitemap URLs broken:\n" + "\n".join(failures)
|
|
)
|