fix: update test fixtures for SQLite storage migration
Some checks failed
Lint & Test / test (push) Failing after 1m33s
Some checks failed
Lint & Test / test (push) Failing after 1m33s
All store tests were passing file paths instead of Database objects after the JSON-to-SQLite migration. Updated fixtures to create temp Database instances, rewrote backup e2e tests for binary .db format, and fixed config tests for the simplified StorageConfig.
This commit is contained in:
@@ -18,8 +18,8 @@ from wled_controller.storage.automation_store import AutomationStore
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(tmp_path) -> AutomationStore:
|
||||
return AutomationStore(str(tmp_path / "automations.json"))
|
||||
def store(tmp_db) -> AutomationStore:
|
||||
return AutomationStore(tmp_db)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -240,16 +240,18 @@ class TestAutomationNameUniqueness:
|
||||
|
||||
class TestAutomationPersistence:
|
||||
def test_persist_and_reload(self, tmp_path):
|
||||
path = str(tmp_path / "auto_persist.json")
|
||||
s1 = AutomationStore(path)
|
||||
from wled_controller.storage.database import Database
|
||||
db = Database(tmp_path / "auto_persist.db")
|
||||
s1 = AutomationStore(db)
|
||||
a = s1.create_automation(
|
||||
name="Persist",
|
||||
conditions=[WebhookCondition(token="t1")],
|
||||
)
|
||||
aid = a.id
|
||||
|
||||
s2 = AutomationStore(path)
|
||||
s2 = AutomationStore(db)
|
||||
loaded = s2.get_automation(aid)
|
||||
assert loaded.name == "Persist"
|
||||
assert len(loaded.conditions) == 1
|
||||
assert isinstance(loaded.conditions[0], WebhookCondition)
|
||||
db.close()
|
||||
|
||||
@@ -14,13 +14,16 @@ from wled_controller.storage.device_store import Device, DeviceStore
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_storage(tmp_path) -> Path:
|
||||
return tmp_path / "devices.json"
|
||||
def tmp_db(tmp_path):
|
||||
from wled_controller.storage.database import Database
|
||||
db = Database(tmp_path / "test.db")
|
||||
yield db
|
||||
db.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(temp_storage) -> DeviceStore:
|
||||
return DeviceStore(temp_storage)
|
||||
def store(tmp_db) -> DeviceStore:
|
||||
return DeviceStore(tmp_db)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -240,23 +243,29 @@ class TestDeviceNameUniqueness:
|
||||
|
||||
|
||||
class TestDevicePersistence:
|
||||
def test_persistence_across_instances(self, temp_storage):
|
||||
s1 = DeviceStore(temp_storage)
|
||||
def test_persistence_across_instances(self, tmp_path):
|
||||
from wled_controller.storage.database import Database
|
||||
db = Database(tmp_path / "persist.db")
|
||||
s1 = DeviceStore(db)
|
||||
d = s1.create_device(name="Persist", url="http://p", led_count=77)
|
||||
did = d.id
|
||||
|
||||
s2 = DeviceStore(temp_storage)
|
||||
s2 = DeviceStore(db)
|
||||
loaded = s2.get_device(did)
|
||||
assert loaded.name == "Persist"
|
||||
assert loaded.led_count == 77
|
||||
db.close()
|
||||
|
||||
def test_update_persists(self, temp_storage):
|
||||
s1 = DeviceStore(temp_storage)
|
||||
def test_update_persists(self, tmp_path):
|
||||
from wled_controller.storage.database import Database
|
||||
db = Database(tmp_path / "persist2.db")
|
||||
s1 = DeviceStore(db)
|
||||
d = s1.create_device(name="Before", url="http://x", led_count=10)
|
||||
s1.update_device(d.id, name="After")
|
||||
|
||||
s2 = DeviceStore(temp_storage)
|
||||
s2 = DeviceStore(db)
|
||||
assert s2.get_device(d.id).name == "After"
|
||||
db.close()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -266,7 +275,9 @@ class TestDevicePersistence:
|
||||
|
||||
class TestDeviceThreadSafety:
|
||||
def test_concurrent_creates(self, tmp_path):
|
||||
s = DeviceStore(tmp_path / "conc.json")
|
||||
from wled_controller.storage.database import Database
|
||||
db = Database(tmp_path / "conc.db")
|
||||
s = DeviceStore(db)
|
||||
errors = []
|
||||
|
||||
def _create(i):
|
||||
|
||||
@@ -11,8 +11,8 @@ from wled_controller.storage.key_colors_output_target import (
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(tmp_path) -> OutputTargetStore:
|
||||
return OutputTargetStore(str(tmp_path / "output_targets.json"))
|
||||
def store(tmp_db) -> OutputTargetStore:
|
||||
return OutputTargetStore(tmp_db)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -193,8 +193,10 @@ class TestOutputTargetQueries:
|
||||
|
||||
class TestOutputTargetPersistence:
|
||||
def test_persist_and_reload(self, tmp_path):
|
||||
path = str(tmp_path / "ot_persist.json")
|
||||
s1 = OutputTargetStore(path)
|
||||
from wled_controller.storage.database import Database
|
||||
db_path = str(tmp_path / "ot_persist.db")
|
||||
db = Database(db_path)
|
||||
s1 = OutputTargetStore(db)
|
||||
t = s1.create_target(
|
||||
"Persist", "led",
|
||||
device_id="dev_1",
|
||||
@@ -203,8 +205,9 @@ class TestOutputTargetPersistence:
|
||||
)
|
||||
tid = t.id
|
||||
|
||||
s2 = OutputTargetStore(path)
|
||||
s2 = OutputTargetStore(db)
|
||||
loaded = s2.get_target(tid)
|
||||
assert loaded.name == "Persist"
|
||||
assert isinstance(loaded, WledOutputTarget)
|
||||
assert loaded.tags == ["tv"]
|
||||
db.close()
|
||||
|
||||
@@ -7,8 +7,8 @@ from wled_controller.storage.sync_clock_store import SyncClockStore
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(tmp_path) -> SyncClockStore:
|
||||
return SyncClockStore(str(tmp_path / "sync_clocks.json"))
|
||||
def store(tmp_db) -> SyncClockStore:
|
||||
return SyncClockStore(tmp_db)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -149,12 +149,14 @@ class TestSyncClockNameUniqueness:
|
||||
|
||||
class TestSyncClockPersistence:
|
||||
def test_persist_and_reload(self, tmp_path):
|
||||
path = str(tmp_path / "sc_persist.json")
|
||||
s1 = SyncClockStore(path)
|
||||
from wled_controller.storage.database import Database
|
||||
db = Database(tmp_path / "sc_persist.db")
|
||||
s1 = SyncClockStore(db)
|
||||
c = s1.create_clock(name="Persist", speed=2.5)
|
||||
cid = c.id
|
||||
|
||||
s2 = SyncClockStore(path)
|
||||
s2 = SyncClockStore(db)
|
||||
loaded = s2.get_clock(cid)
|
||||
assert loaded.name == "Persist"
|
||||
assert loaded.speed == 2.5
|
||||
db.close()
|
||||
|
||||
@@ -14,8 +14,8 @@ from wled_controller.storage.value_source_store import ValueSourceStore
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def store(tmp_path) -> ValueSourceStore:
|
||||
return ValueSourceStore(str(tmp_path / "value_sources.json"))
|
||||
def store(tmp_db) -> ValueSourceStore:
|
||||
return ValueSourceStore(tmp_db)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -247,13 +247,15 @@ class TestValueSourceNameUniqueness:
|
||||
|
||||
class TestValueSourcePersistence:
|
||||
def test_persist_and_reload(self, tmp_path):
|
||||
path = str(tmp_path / "vs_persist.json")
|
||||
s1 = ValueSourceStore(path)
|
||||
from wled_controller.storage.database import Database
|
||||
db = Database(tmp_path / "vs_persist.db")
|
||||
s1 = ValueSourceStore(db)
|
||||
src = s1.create_source("Persist", "static", value=0.42)
|
||||
sid = src.id
|
||||
|
||||
s2 = ValueSourceStore(path)
|
||||
s2 = ValueSourceStore(db)
|
||||
loaded = s2.get_source(sid)
|
||||
assert loaded.name == "Persist"
|
||||
assert isinstance(loaded, StaticValueSource)
|
||||
assert loaded.value == 0.42
|
||||
db.close()
|
||||
|
||||
Reference in New Issue
Block a user