Files
led-controller/test/api/test_bundles.py
jimmyandClaude Opus 5.5 24d3c1149d test(api): share one profile() fixture in conftest
Six test files each defined the same profile() fixture. It now lives once
in conftest.py, with test_profiles.py's 201 check on create.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 01:35:56 +13:00

73 lines
3.2 KiB
Python

"""Import/export bundles (main's tests/test_profile_bundle.py over HTTP)."""
from helpers import new_id
def test_profile_round_trip(c, profile):
presets = c.get("/presets").json()
a = next(iter(presets))
sid = new_id(c.post("/sequences", json={"name": "pytest-seq", "lanes": [[{"preset_id": a, "beats": 2}]]}))
zid = c.get(f"/profiles/{profile}").json()["zones"][0]
c.put(f"/zones/{zid}", json={"sequence_ids": [sid]})
c.put(f"/palettes/{c.get(f'/profiles/{profile}').json()['palette_id']}", json={"colors": ["#123456"]})
bundle = c.get(f"/profiles/{profile}/export").json()
assert bundle["version"] == 1 and bundle["kind"] == "profile"
assert bundle["palette"]["colors"] == ["#123456"]
assert zid in bundle["zones"] and sid in bundle["sequences"]
assert set(presets) == set(bundle["presets"])
resp = c.post("/profiles/import", json={"bundle": bundle, "name": "pytest-imported"})
assert resp.status_code == 201
new = resp.json()["id"]
assert resp.json()[new]["name"] == "pytest-imported"
assert c.get("/profiles/current").json()["id"] == new # applied by default
imported = c.get("/presets").json()
assert len(imported) == len(presets) and not set(imported) & set(presets)
nz = c.get(f"/profiles/{new}").json()["zones"]
assert len(nz) == 1 and nz[0] != zid
zone = c.get(f"/zones/{nz[0]}").json()
new_sid = zone["sequence_ids"][0]
assert new_sid != sid
seq = c.get(f"/sequences/{new_sid}").json()
assert seq["lanes"][0][0]["preset_id"] in imported
pal = c.get(f"/palettes/{c.get(f'/profiles/{new}').json()['palette_id']}").json()
assert pal["colors"] == ["#123456"]
c.delete(f"/profiles/{new}")
def test_profile_import_rejects_other_bundles(c, profile):
assert c.post("/profiles/import", json={"version": 2, "kind": "profile", "profile": {}}).status_code == 400
assert c.post("/profiles/import", json={"version": 1, "kind": "preset", "profile": {}}).status_code == 400
assert c.post("/profiles/import", json={"version": 1, "kind": "profile"}).status_code == 400
def test_export_unknown_profile(c):
assert c.get("/profiles/999999/export").status_code == 404
def test_preset_round_trip(c, profile):
a = next(iter(c.get("/presets").json()))
bundle = c.get(f"/presets/{a}/export").json()
assert bundle["kind"] == "preset"
resp = c.post("/presets/import", json={"bundle": bundle})
assert resp.status_code == 201
new = new_id(resp)
assert new != a
assert resp.json()[new]["name"] == bundle["preset"]["name"]
assert resp.json()[new]["profile_id"] == profile
assert c.post("/presets/import", json={"kind": "sequence"}).status_code == 400
def test_sequence_round_trip(c, profile):
a = next(iter(c.get("/presets").json()))
sid = new_id(c.post("/sequences", json={"name": "pytest-seq", "lanes": [[{"preset_id": a, "beats": 3}]]}))
bundle = c.get(f"/sequences/{sid}/export").json()
assert bundle["kind"] == "sequence" and a in bundle["presets"]
resp = c.post("/sequences/import", json={"bundle": bundle})
assert resp.status_code == 201
new = new_id(resp)
step = resp.json()[new]["lanes"][0][0]
assert step["beats"] == 3 and step["preset_id"] != a
assert step["preset_id"] in c.get("/presets").json()