Files
led-controller/test/api/test_routes.py
T
jimmyandClaude Opus 5.5 06953028ab feat(ui): driver settings and code updates over ESP-NOW
Settings gets a Driver tab (/settings/editor). It sends a driver its settings through PUT /devices/<id>, which now forwards name too, and runs the tools/driver_ota.py session from the browser. The firmware embeds the led-driver files and a manifest of their hashes, because crypto.subtle is unavailable over plain HTTP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 23:51:41 +13:00

68 lines
1.9 KiB
Python

import hashlib
import pytest
def test_index(c):
resp = c.get("/")
assert resp.status_code == 200
assert "LED Controller" in resp.text
def test_favicon(c):
assert c.get("/favicon.ico").status_code == 204
@pytest.mark.parametrize("path", ["style.css", "zones.js", "presets.js", "profiles.js", "devices.js",
"settings_editor.js"])
def test_static(c, path):
assert c.get(f"/static/{path}").status_code == 200
def test_settings_editor_page(c):
resp = c.get("/settings/editor")
assert resp.status_code == 200
assert "espnow-send" in resp.text
def test_driver_files(c):
files = c.get("/static/driver/manifest.json").json()["files"]
assert any(f["path"] == "main.py" for f in files)
for f in (files[0], files[-1]):
body = c.get(f"/static/driver/{f['path']}").content
assert hashlib.sha256(body).hexdigest() == f["sha"]
def test_status_reset_reason(c):
assert c.get("/status").json()["reset_reason"]
def test_settings_page(c):
resp = c.get("/settings/page")
assert resp.status_code == 200
assert "LED Controller" in resp.text
def test_ws_rejects_plain_get(c):
# A websocket endpoint refuses a request that is not an upgrade
resp = c.get("/ws")
assert resp.status_code in {400, 401, 403, 405, 426}
def test_ws_forwards_messages(base_url):
# From main's test_main_routes: the socket greets with the (empty) Wi-Fi snapshot and takes v1 messages
import websocket
ws = websocket.create_connection(base_url.replace("http", "ws", 1) + "/ws", timeout=5)
try:
import json
snapshot = json.loads(ws.recv())
assert snapshot["type"] == "device_tcp_snapshot"
assert isinstance(snapshot["connected_ips"], list)
ws.send('{"v":"1","select":["off"],"groups":["pytest-none"]}')
ws.send("not json")
assert "error" in json.loads(ws.recv())
finally:
ws.close()