HTTP tests against a running controller (make test-api HOST=ip). They snapshot every collection through /db and restore it afterwards. v1 behaviour v2 does not have yet is marked as a strict xfail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
131 lines
4.2 KiB
Python
131 lines
4.2 KiB
Python
import pytest
|
|
|
|
from helpers import missing, new_id, unique
|
|
|
|
|
|
@pytest.fixture
|
|
def profile(c):
|
|
pid = new_id(c.post("/profiles", json={"name": unique("pytest-profile")}))
|
|
assert c.post(f"/profiles/{pid}/apply").status_code == 200
|
|
yield pid
|
|
c.delete(f"/profiles/{pid}")
|
|
|
|
|
|
@pytest.fixture
|
|
def zone(c, profile):
|
|
name = unique("pytest-zone")
|
|
resp = c.post("/zones", json={"name": name, "names": ["pytest-a", "pytest-b"]})
|
|
assert resp.status_code == 201
|
|
zid = new_id(resp)
|
|
yield zid
|
|
c.delete(f"/zones/{zid}")
|
|
|
|
|
|
@missing("v1 zone list shape and profile zone order")
|
|
def test_list(c, profile, zone):
|
|
resp = c.get("/zones")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert zone in data["zones"]
|
|
assert zone in data["zone_order"]
|
|
assert str(data["profile_id"]) == profile
|
|
assert "current_zone_id" in data
|
|
|
|
|
|
@missing("adding new zones to the current profile")
|
|
def test_create_adds_to_profile(c, profile, zone):
|
|
assert zone in c.get(f"/profiles/{profile}").json()["zones"]
|
|
|
|
|
|
@missing("zone validation")
|
|
def test_create_requires_name(c, profile):
|
|
assert c.post("/zones", json={"names": ["1"]}).status_code == 400
|
|
|
|
|
|
def test_get(c, zone):
|
|
resp = c.get(f"/zones/{zone}")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["name"].startswith("pytest-zone")
|
|
|
|
|
|
@missing("zone set-current")
|
|
def test_set_current(c, zone):
|
|
resp = c.post(f"/zones/{zone}/set-current")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["zone_id"] == zone
|
|
assert c.cookies.get("current_zone") == zone
|
|
resp = c.get("/zones/current")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["zone_id"] == zone
|
|
|
|
|
|
@missing("zone set-current")
|
|
def test_set_current_unknown(c):
|
|
assert c.post("/zones/999999/set-current").status_code == 404
|
|
|
|
|
|
def test_edit_workflow(c, zone):
|
|
# From v1 tests/test_endpoints.py test_zone_edit_workflow
|
|
resp = c.put(f"/zones/{zone}", json={"name": "Edited Zone Name", "names": ["2", "3", "4"]})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["name"] == "Edited Zone Name"
|
|
assert resp.json()["names"] == ["2", "3", "4"]
|
|
stored = c.get(f"/zones/{zone}").json()
|
|
assert stored["name"] == "Edited Zone Name"
|
|
assert stored["names"] == ["2", "3", "4"]
|
|
|
|
|
|
@missing("zone clone")
|
|
def test_clone(c, profile, zone):
|
|
resp = c.post(f"/zones/{zone}/clone", json={"name": "pytest-zone-clone"})
|
|
assert resp.status_code == 201
|
|
clone = new_id(resp)
|
|
assert clone != zone
|
|
rec = c.get(f"/zones/{clone}").json()
|
|
assert rec["name"] == "pytest-zone-clone"
|
|
assert rec["names"] == ["pytest-a", "pytest-b"]
|
|
assert clone in c.get(f"/profiles/{profile}").json()["zones"]
|
|
assert c.delete(f"/zones/{clone}").status_code == 200
|
|
|
|
|
|
@missing("zone clone")
|
|
def test_clone_default_name(c, zone):
|
|
resp = c.post(f"/zones/{zone}/clone", json={})
|
|
clone = new_id(resp)
|
|
assert resp.json()[clone]["name"].endswith(" Copy")
|
|
c.delete(f"/zones/{clone}")
|
|
|
|
|
|
@missing("zone content-fragment")
|
|
def test_content_fragment(c, zone):
|
|
resp = c.get(f"/zones/{zone}/content-fragment", headers={"HX-Request": "true", "Accept": "text/html"})
|
|
assert resp.status_code == 200
|
|
assert f'data-zone-id="{zone}"' in resp.text
|
|
|
|
|
|
@missing("removing deleted zones from the profile")
|
|
def test_delete_removes_from_profile(c, profile):
|
|
zid = new_id(c.post("/zones", json={"name": unique("pytest-zone"), "names": ["1"]}))
|
|
assert c.delete(f"/zones/{zid}").status_code == 200
|
|
assert c.get(f"/zones/{zid}").status_code == 404
|
|
assert zid not in c.get(f"/profiles/{profile}").json()["zones"]
|
|
|
|
|
|
def test_play_requires_preset(c, zone):
|
|
assert c.post(f"/zones/{zone}/play", json={}).status_code == 400
|
|
|
|
|
|
def test_play_unknown_preset(c, zone):
|
|
assert c.post(f"/zones/{zone}/play", json={"preset_id": "nope"}).status_code == 404
|
|
|
|
|
|
@missing("zone stop reply ({stopped})")
|
|
def test_play_and_stop(c, zone):
|
|
preset = new_id(c.post("/presets", json={"name": "pytest-on", "pattern": "on", "colors": ["#ff0000"]}))
|
|
resp = c.post(f"/zones/{zone}/play", json={"preset_id": preset})
|
|
assert resp.status_code == 200, resp.text
|
|
assert c.get("/zones/engine/status").status_code == 200
|
|
resp = c.post(f"/zones/{zone}/stop")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["stopped"] is True
|