Home intro from retoor as editable site_intro setting; fix settings upsert

This commit is contained in:
2026-10-05 11:12:18 +02:00
parent 3fb47bf401
commit bbdecdc95b
14 changed files with 131 additions and 16 deletions
+46
View File
@@ -13,3 +13,49 @@ def test_unknown_page_is_404(anon):
response = anon.get("/bestaat-niet-xyz")
assert response.status_code == 404
assert anon.get("/bestaat-niet-xyz", headers={"Accept": "application/json"}).json()["error"]
def _intro_section(html):
from bs4 import BeautifulSoup
return BeautifulSoup(html, "html.parser").select_one("section.hero [data-intro]")
def test_intro_renders_on_home(anon):
from molodetz.constants import SITE_INTRO_SEED
intro = _intro_section(anon.get("/").text)
assert intro is not None
paragraphs = intro.find_all("p", recursive=False)
assert len(paragraphs) == len([block for block in SITE_INTRO_SEED.split("\n\n") if block.strip()])
assert paragraphs[0].get_text(" ", strip=True).startswith("I wrote more code than you. I wrote more code than the best programmer you know.")
assert paragraphs[-1].get_text(strip=True) == "Will you be the one that will be replaced? Or will you be the one that will replace. Look at the guy next to you."
assert len(paragraphs[1].find_all("br")) == 5
text = intro.get_text(" ", strip=True)
for fixed in ("especially since it was", "Well, for starters", "development environment", "more divided in skills", "i triple down", "No professional texts", "it must have been worth", "measure its usage", "Buy now.", 'Vibe "Coders"'):
assert fixed in text, fixed
for typo in ("sicne", "deelopment", "devided", "tripple", "teksts", "have be worth", "it s usage", "\u1e82"):
assert typo not in text, typo
assert "<!--" not in str(intro)
def test_intro_json_face(anon):
data = anon.get("/", headers={"Accept": "application/json"}).json()
assert data["intro"].startswith("I wrote more code than you.")
def test_admin_can_edit_intro(admin, anon):
original = admin.get("/admin/settings", headers={"Accept": "application/json"}).json()["settings"]["site_intro"]
try:
response = admin.post("/admin/settings", json={"site_intro": "Eerste regel.\n\nTweede alinea\nmet een regel erbij."}, headers={"Accept": "application/json"})
assert response.status_code == 200
intro = _intro_section(anon.get("/").text)
assert intro.find("p").get_text() == "Eerste regel."
assert intro.find_all("p")[1].find("br") is not None
form = admin.post("/admin/settings", data={"site_intro": "Via formulier.\r\n\r\nRegel een\r\nregel twee"})
assert form.status_code in (302, 303)
stored = admin.get("/admin/settings", headers={"Accept": "application/json"}).json()["settings"]["site_intro"]
assert stored == "Via formulier.\n\nRegel een\nregel twee"
finally:
admin.post("/admin/settings", json={"site_intro": original}, headers={"Accept": "application/json"})
assert _intro_section(anon.get("/").text).find("p").get_text(" ", strip=True).startswith("I wrote more code than you.")