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>
102 lines
3.7 KiB
Python
102 lines
3.7 KiB
Python
import pytest
|
|
|
|
from helpers import new_id, unique
|
|
|
|
# Presets every new profile is seeded with (main's controllers/profile.py)
|
|
SEEDED = {"on", "off", "rainbow", "Colour Cycle", "transition", "flicker", "flame", "twinkle"}
|
|
|
|
|
|
@pytest.fixture
|
|
def profile(c):
|
|
resp = c.post("/profiles", json={"name": unique("pytest-profile")})
|
|
assert resp.status_code == 201
|
|
pid = new_id(resp)
|
|
assert c.post(f"/profiles/{pid}/apply").status_code == 200
|
|
yield pid
|
|
c.delete(f"/profiles/{pid}")
|
|
|
|
|
|
def test_list(c, profile):
|
|
resp = c.get("/profiles")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert profile in data["profiles"]
|
|
assert data["current_profile_id"] == profile
|
|
|
|
|
|
def test_apply_sets_current(c, profile):
|
|
resp = c.get("/profiles/current")
|
|
assert resp.status_code == 200
|
|
assert str(resp.json()["id"]) == profile
|
|
assert resp.json()["profile"]["name"].startswith("pytest-profile")
|
|
|
|
|
|
def test_apply_unknown_profile(c):
|
|
assert c.post("/profiles/999999/apply").status_code == 404
|
|
|
|
|
|
def test_new_profile_is_seeded(c, profile):
|
|
presets = c.get("/presets").json()
|
|
assert SEEDED <= {p["name"] for p in presets.values()}
|
|
rec = c.get(f"/profiles/{profile}").json()
|
|
assert rec["palette_id"] in c.get("/palettes").json()
|
|
zones = rec["zones"]
|
|
assert len(zones) == 1
|
|
zone = c.get(f"/zones/{zones[0]}").json()
|
|
assert zone["name"] == "default"
|
|
assert set(zone["presets_flat"]) == set(presets)
|
|
|
|
|
|
def test_put_current(c, profile):
|
|
name = unique("pytest-renamed")
|
|
assert c.put("/profiles/current", json={"name": name}).status_code == 200
|
|
assert c.get(f"/profiles/{profile}").json()["name"] == name
|
|
|
|
|
|
def test_put(c, profile):
|
|
name = unique("pytest-renamed")
|
|
resp = c.put(f"/profiles/{profile}", json={"name": name})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["name"] == name
|
|
|
|
|
|
def test_clone(c, profile):
|
|
name = unique("pytest-profile-clone")
|
|
resp = c.post(f"/profiles/{profile}/clone", json={"name": name})
|
|
assert resp.status_code == 201
|
|
clone = new_id(resp)
|
|
assert clone != profile
|
|
assert resp.json()[clone]["name"] == name
|
|
src_presets = c.get("/presets").json()
|
|
|
|
assert c.post(f"/profiles/{clone}/apply").status_code == 200
|
|
cloned_presets = c.get("/presets").json()
|
|
# The clone gets its own copies of the presets, zones and palette
|
|
assert not set(cloned_presets) & set(src_presets)
|
|
assert sorted(p["name"] for p in cloned_presets.values()) == sorted(p["name"] for p in src_presets.values())
|
|
src, dst = c.get(f"/profiles/{profile}").json(), c.get(f"/profiles/{clone}").json()
|
|
assert dst["palette_id"] != src["palette_id"]
|
|
assert len(dst["zones"]) == len(src["zones"]) and not set(dst["zones"]) & set(src["zones"])
|
|
|
|
assert c.delete(f"/profiles/{clone}").status_code == 200
|
|
|
|
|
|
def test_seeded_rainbow_uses_colour_cycle(c, profile):
|
|
presets = c.get("/presets").json().values()
|
|
assert next(p for p in presets if p["name"] == "rainbow")["pattern"] == "colour_cycle"
|
|
|
|
|
|
def test_delete(c):
|
|
pid = new_id(c.post("/profiles", json={"name": unique("pytest-profile")}))
|
|
c.post(f"/profiles/{pid}/apply")
|
|
prof = c.get(f"/profiles/{pid}").json()
|
|
preset_ids = set(c.get("/presets").json())
|
|
seq = new_id(c.post("/sequences", json={"name": "pytest-seq"}))
|
|
assert c.delete(f"/profiles/{pid}").status_code == 200
|
|
assert c.get(f"/profiles/{pid}").status_code == 404
|
|
# its presets, sequences, zones and palette go with it, so a profile that reuses the id starts clean
|
|
assert not preset_ids & set(c.get("/db/preset").json())
|
|
assert not set(prof["zones"]) & set(c.get("/zones").json()["zones"])
|
|
assert prof["palette_id"] not in c.get("/palettes").json()
|
|
assert seq not in c.get("/db/sequence").json()
|