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>
31 lines
930 B
Python
31 lines
930 B
Python
"""Tests for RSS, sitemap, and robots.txt."""
|
|
|
|
import xml.etree.ElementTree as ET
|
|
|
|
|
|
def test_feed_xml(client):
|
|
r = client.get("/feed.xml")
|
|
assert r.status_code == 200
|
|
root = ET.fromstring(r.text)
|
|
items = root.findall(".//item")
|
|
assert len(items) >= 10
|
|
first = items[0]
|
|
assert first.findtext("title")
|
|
assert first.findtext("link", "").startswith("https://kennethreitz.org/")
|
|
|
|
|
|
def test_sitemap_xml(client):
|
|
r = client.get("/sitemap.xml")
|
|
assert r.status_code == 200
|
|
root = ET.fromstring(r.text)
|
|
ns = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
|
|
locs = [el.text for el in root.findall(".//sm:loc", ns)]
|
|
assert len(locs) > 200
|
|
assert all(loc.startswith("https://kennethreitz.org") for loc in locs)
|
|
|
|
|
|
def test_robots_txt(client):
|
|
r = client.get("/robots.txt")
|
|
assert r.status_code == 200
|
|
assert "Sitemap: https://kennethreitz.org/sitemap.xml" in r.text
|