Files
led-controller/test/api/test_routes.py
T
jimmyandClaude Opus 5.5 bfeeb958df feat: main's import/export, zones, audio API and web UI
Profiles, presets and sequences export and import as main's bundles.
Zones carry group_ids, preset_group_ids, sequence_ids, content_kind and
brightness; profiles seed rainbow as colour_cycle, and deleting a
profile also deletes its sequences. Groups, zones and sequences written
by older versions are migrated at boot.

/api/audio (status, event stream, start/stop, reset, anchor-bar,
devices) maps main's audio detector onto the mic's beat detector. Audio
start/stop picks whether mic beats or the BPM clock time sequences; the
clock's beats also go to the drivers while the mic is off.
/ws now greets from a post-handshake callback (httpd does not call the
handler for the upgrade).

The web UI is main's, plus v2's outputs editor, list search and
hostname/static IP settings; the bridge, Wi-Fi AP and led-tool parts
are gone. API tests follow main's behaviour (119 pass on the board).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 20:34:22 +13:00

47 lines
1.3 KiB
Python

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"])
def test_static(c, path):
assert c.get(f"/static/{path}").status_code == 200
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()