from datetime import datetime from dashboard import create_app def test_dashboard_renders_locations(): state = { "running": True, "started_at": datetime(2025, 1, 1, 0, 0, 0), "last_type": "420", "last_attempt_at": datetime(2025, 1, 1, 0, 1, 2), "last_success_at": datetime(2025, 1, 1, 0, 1, 3), "last_status_code": 204, "last_error": None, "last_locations": ["Nowhere", "Somewhere"], } app = create_app( get_state=lambda: state, get_next_event=lambda: {"type": "reminder", "at": datetime(2025, 1, 1, 0, 15, 0)}, ) client = app.test_client() resp = client.get("/") assert resp.status_code == 200 body = resp.data.decode("utf-8") assert "thc-webhook" in body assert "Locations" in body assert "
  • Nowhere
  • " in body assert "
  • Somewhere
  • " in body def test_admin_roundtrip(tmp_path, monkeypatch): templates_path = tmp_path / "templates.json" monkeypatch.setenv("TEMPLATES_PATH", str(templates_path)) app = create_app( get_state=lambda: {}, get_next_event=lambda: {"type": "reminder", "at": datetime(2025, 1, 1, 0, 15, 0)}, ) app.config["TEMPLATES_PATH"] = str(templates_path) client = app.test_client() # GET admin should render resp = client.get("/admin") assert resp.status_code == 200 # POST should save form = { "reminder__text": "R", "reminder__color": "#e67e22", "reminder__image_url": "", "420__text": "B", "420__color": "0x2ecc71", "420__image_url": "http://example.com/img.png", "reminder_halftime__text": "H", "reminder_halftime__color": "15158306", "reminder_halftime__image_url": "", "halftime__text": "HT", "halftime__color": "3066993", "halftime__image_url": "", } resp = client.post("/admin", data=form) assert resp.status_code == 200 assert templates_path.exists()