From 24d3c1149dd7a1a235890a6b8f16b5b1e785239a Mon Sep 17 00:00:00 2001 From: jimmy Date: Wed, 4 Nov 2026 01:35:56 +1300 Subject: [PATCH] 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 --- test/api/conftest.py | 13 +++++++++++++ test/api/test_bundles.py | 12 +----------- test/api/test_groups.py | 8 -------- test/api/test_presets.py | 8 -------- test/api/test_profiles.py | 12 ------------ test/api/test_sequences.py | 8 -------- test/api/test_zones.py | 8 -------- 7 files changed, 14 insertions(+), 55 deletions(-) diff --git a/test/api/conftest.py b/test/api/conftest.py index 4dbb75f..5bbeec5 100644 --- a/test/api/conftest.py +++ b/test/api/conftest.py @@ -10,6 +10,8 @@ import os import pytest import requests +from helpers import new_id, unique + # Store collections (main/store.c NAMES), all reachable through GET/PUT /db/ COLLECTIONS = ["device", "zone", "preset", "profile", "palette", "pattern", "sequence", "scene", "group", "output", "settings"] @@ -55,6 +57,17 @@ def c(base_url): yield client +@pytest.fixture +def profile(c): + """A new profile, made current for the test and deleted afterwards.""" + 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}") + + @pytest.fixture(scope="session", autouse=True) def restore_db(request): """Snapshot every collection before the run and write it back afterwards.""" diff --git a/test/api/test_bundles.py b/test/api/test_bundles.py index fc49016..0839203 100644 --- a/test/api/test_bundles.py +++ b/test/api/test_bundles.py @@ -1,16 +1,6 @@ """Import/export bundles (main's tests/test_profile_bundle.py over HTTP).""" -import pytest - -from helpers import 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}") +from helpers import new_id def test_profile_round_trip(c, profile): diff --git a/test/api/test_groups.py b/test/api/test_groups.py index e211f78..b46853b 100644 --- a/test/api/test_groups.py +++ b/test/api/test_groups.py @@ -7,14 +7,6 @@ from helpers import find_id_by_field, new_id, unique MAC = "aabbccddee01" # made up: no driver answers it -@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 device(c): c.delete(f"/devices/{MAC}") diff --git a/test/api/test_presets.py b/test/api/test_presets.py index 45d82ad..c4a105e 100644 --- a/test/api/test_presets.py +++ b/test/api/test_presets.py @@ -3,14 +3,6 @@ import pytest from helpers import 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 preset(c, profile): resp = c.post("/presets", json={"name": unique("pytest-preset"), "pattern": "on", diff --git a/test/api/test_profiles.py b/test/api/test_profiles.py index 5d6e614..472f3b5 100644 --- a/test/api/test_profiles.py +++ b/test/api/test_profiles.py @@ -1,21 +1,9 @@ -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 diff --git a/test/api/test_sequences.py b/test/api/test_sequences.py index 2e2756d..c78bce5 100644 --- a/test/api/test_sequences.py +++ b/test/api/test_sequences.py @@ -10,14 +10,6 @@ from helpers import find_id_by_field, new_id, unique BEAT_S = 0.3 -@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 clock(c): """Beats from the clock at 200 BPM; mic timing is restored afterwards.""" diff --git a/test/api/test_zones.py b/test/api/test_zones.py index 0048608..cac7d1a 100644 --- a/test/api/test_zones.py +++ b/test/api/test_zones.py @@ -3,14 +3,6 @@ import pytest from helpers import 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")