Refactor: extract edit UI HTML into bincio/edit/templates/edit.html

The 285-line _HTML string literal in edit/server.py is replaced by a
template file loaded at request time. The route handler is unchanged in
behaviour — it still substitutes __SITE_URL__, __SPORT_OPTIONS__, and
__STAT_CHECKBOXES__ before returning the response.

Five new tests cover: 200 response, form presence, site_url injection,
no unresolved placeholders, and template file existence on disk.
This commit is contained in:
Davide Scaini
2026-05-13 23:19:19 +02:00
parent 9dd533825f
commit 2ec4d9157c
4 changed files with 318 additions and 291 deletions
+31
View File
@@ -156,3 +156,34 @@ class TestDemEndpoint:
monkeypatch.setattr(edit_server, "dem_url", "https://api.open-elevation.com")
r = CLIENT.post("/api/activity/../../evil/recalculate-elevation/dem")
assert r.status_code in (400, 404, 422)
# ── /edit/{activity_id} HTML template ────────────────────────────────────────
class TestEditPage:
AID = "2024-01-01T080000Z-my-ride"
def test_returns_200_html(self):
r = CLIENT.get(f"/edit/{self.AID}")
assert r.status_code == 200
assert r.headers["content-type"].startswith("text/html")
def test_contains_form(self):
r = CLIENT.get(f"/edit/{self.AID}")
assert '<form id="form"' in r.text
def test_site_url_placeholder_replaced(self, monkeypatch):
monkeypatch.setattr(edit_server, "site_url", "http://localhost:9999")
r = CLIENT.get(f"/edit/{self.AID}")
assert "http://localhost:9999" in r.text
assert "__SITE_URL__" not in r.text
def test_no_unresolved_placeholders(self):
r = CLIENT.get(f"/edit/{self.AID}")
for token in ("__SITE_URL__", "__SPORT_OPTIONS__", "__STAT_CHECKBOXES__"):
assert token not in r.text, f"Unresolved placeholder: {token}"
def test_template_file_exists_on_disk(self):
from pathlib import Path
template = Path(edit_server.__file__).parent / "templates" / "edit.html"
assert template.exists(), f"Template not found at {template}"