e30920067f
- Updated docker-compose.yml to expose dashboard on port 8080. - Enhanced main.py with timezone database caching and improved state management. - Introduced a minimal dashboard using Flask to display webhook status and notifications. - Added templates.json for customizable embed messages in Discord notifications. - Created templates.py for loading and saving notification templates. - Implemented tests for dashboard rendering and main functionality. - Added requirements for Flask and tzdata to support new features. - Included test cases for timezone handling and template management.
66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
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 "<li>Nowhere</li>" in body
|
|
assert "<li>Somewhere</li>" 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()
|