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>
This commit is contained in:
1 parent
16a3d3aa26
commit
24d3c1149d
7 files changed
+14
-55
No files matched your search
@@ -10,6 +10,8 @@ import os
|
|||||||
import pytest
|
import pytest
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
from helpers import new_id, unique
|
||||||
|
|
||||||
# Store collections (main/store.c NAMES), all reachable through GET/PUT /db/<name>
|
# Store collections (main/store.c NAMES), all reachable through GET/PUT /db/<name>
|
||||||
COLLECTIONS = ["device", "zone", "preset", "profile", "palette", "pattern",
|
COLLECTIONS = ["device", "zone", "preset", "profile", "palette", "pattern",
|
||||||
"sequence", "scene", "group", "output", "settings"]
|
"sequence", "scene", "group", "output", "settings"]
|
||||||
@@ -55,6 +57,17 @@ def c(base_url):
|
|||||||
yield client
|
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)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def restore_db(request):
|
def restore_db(request):
|
||||||
"""Snapshot every collection before the run and write it back afterwards."""
|
"""Snapshot every collection before the run and write it back afterwards."""
|
||||||
|
|||||||
@@ -1,16 +1,6 @@
|
|||||||
"""Import/export bundles (main's tests/test_profile_bundle.py over HTTP)."""
|
"""Import/export bundles (main's tests/test_profile_bundle.py over HTTP)."""
|
||||||
|
|
||||||
import pytest
|
from helpers import new_id
|
||||||
|
|
||||||
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}")
|
|
||||||
|
|
||||||
|
|
||||||
def test_profile_round_trip(c, profile):
|
def test_profile_round_trip(c, profile):
|
||||||
|
|||||||
@@ -7,14 +7,6 @@ from helpers import find_id_by_field, new_id, unique
|
|||||||
MAC = "aabbccddee01" # made up: no driver answers it
|
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
|
@pytest.fixture
|
||||||
def device(c):
|
def device(c):
|
||||||
c.delete(f"/devices/{MAC}")
|
c.delete(f"/devices/{MAC}")
|
||||||
|
|||||||
@@ -3,14 +3,6 @@ import pytest
|
|||||||
from helpers import new_id, unique
|
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
|
@pytest.fixture
|
||||||
def preset(c, profile):
|
def preset(c, profile):
|
||||||
resp = c.post("/presets", json={"name": unique("pytest-preset"), "pattern": "on",
|
resp = c.post("/presets", json={"name": unique("pytest-preset"), "pattern": "on",
|
||||||
|
|||||||
@@ -1,21 +1,9 @@
|
|||||||
import pytest
|
|
||||||
|
|
||||||
from helpers import new_id, unique
|
from helpers import new_id, unique
|
||||||
|
|
||||||
# Presets every new profile is seeded with (main's controllers/profile.py)
|
# Presets every new profile is seeded with (main's controllers/profile.py)
|
||||||
SEEDED = {"on", "off", "rainbow", "Colour Cycle", "transition", "flicker", "flame", "twinkle"}
|
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):
|
def test_list(c, profile):
|
||||||
resp = c.get("/profiles")
|
resp = c.get("/profiles")
|
||||||
assert resp.status_code == 200
|
assert resp.status_code == 200
|
||||||
|
|||||||
@@ -10,14 +10,6 @@ from helpers import find_id_by_field, new_id, unique
|
|||||||
BEAT_S = 0.3
|
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
|
@pytest.fixture
|
||||||
def clock(c):
|
def clock(c):
|
||||||
"""Beats from the clock at 200 BPM; mic timing is restored afterwards."""
|
"""Beats from the clock at 200 BPM; mic timing is restored afterwards."""
|
||||||
|
|||||||
@@ -3,14 +3,6 @@ import pytest
|
|||||||
from helpers import new_id, unique
|
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
|
@pytest.fixture
|
||||||
def zone(c, profile):
|
def zone(c, profile):
|
||||||
name = unique("pytest-zone")
|
name = unique("pytest-zone")
|
||||||
|
|||||||
Reference in new issue
Block a user