Profiles seed presets, a default zone and a palette, and clone with their own copies; deleting a profile removes what it owned. Zones get the v1 list shape, set-current, current, clone and content-fragment. Devices are keyed by MAC with v1 validation and identify. Patterns: definitions, OTA file and manifest, upload, driver, and send over ESP-NOW (the led-driver pattern sources are embedded in the firmware). Pixel outputs get v1 validation and a DDP/Art-Net/sACN test pattern. Sequences, palettes and settings follow v1 replies and validation, and /ws forwards browser messages to the drivers. The resource handlers move out of api.c into res_*.c, patterns.c and outputs.c. cJSON now allocates from PSRAM: the store had grown enough to starve internal RAM and abort the mic at boot. /status reports free_internal. The Wi-Fi AP and led-tool routes are left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
from helpers import unique
|
|
|
|
|
|
def test_definitions(c):
|
|
resp = c.get("/patterns/definitions")
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), dict)
|
|
|
|
|
|
def test_list_includes_driver_patterns(c):
|
|
resp = c.get("/patterns")
|
|
assert resp.status_code == 200
|
|
assert "blink" in resp.json()
|
|
|
|
|
|
def test_crud(c):
|
|
pid = unique("pytest_pattern").replace("-", "_")
|
|
resp = c.post("/patterns", json={"name": pid, "data": {"foo": "bar"}})
|
|
assert resp.status_code == 201
|
|
assert resp.json()["foo"] == "bar"
|
|
resp = c.get(f"/patterns/{pid}")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["foo"] == "bar"
|
|
resp = c.put(f"/patterns/{pid}", json={"baz": 1})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["baz"] == 1
|
|
assert c.delete(f"/patterns/{pid}").status_code == 200
|
|
|
|
|
|
def test_ota_file(c):
|
|
resp = c.get("/patterns/ota/file/blink.py")
|
|
assert resp.status_code == 200
|
|
assert resp.headers["Content-Type"].startswith("text/plain")
|
|
assert "class" in resp.text
|
|
|
|
|
|
def test_ota_file_rejects_builtin(c):
|
|
# on/off are built into the driver firmware, not OTA files
|
|
resp = c.get("/patterns/ota/file/on.py")
|
|
assert resp.status_code == 400
|
|
assert "error" in resp.json()
|
|
|
|
|
|
def test_ota_manifest(c):
|
|
resp = c.get("/patterns/ota/manifest")
|
|
assert resp.status_code == 200
|
|
names = [f["name"] for f in resp.json()["files"]]
|
|
assert "blink.py" in names
|
|
|
|
|
|
def test_send_rejects_builtin(c):
|
|
resp = c.post("/patterns/off/send", json={})
|
|
assert resp.status_code == 400
|
|
assert "error" in resp.json()
|
|
|
|
|
|
def test_upload_rejects_builtin(c):
|
|
resp = c.post("/patterns/upload", json={"name": "on.py", "code": "class On:\n def run(self, p):\n yield\n"})
|
|
assert resp.status_code == 400
|
|
|
|
|
|
def test_driver_rejects_builtin(c):
|
|
resp = c.post("/patterns/driver", json={"name": "off", "code": "class Off:\n def run(self, p):\n yield\n"})
|
|
assert resp.status_code == 400
|