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:
@@ -2,19 +2,22 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from wled_controller.storage.database import Database
|
||||
from wled_controller.storage.device_store import Device, DeviceStore
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def temp_storage(tmp_path):
|
||||
"""Provide temporary storage file."""
|
||||
return tmp_path / "devices.json"
|
||||
def tmp_db(tmp_path):
|
||||
"""Provide a temporary SQLite Database instance."""
|
||||
db = Database(tmp_path / "test.db")
|
||||
yield db
|
||||
db.close()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def device_store(temp_storage):
|
||||
def device_store(tmp_db):
|
||||
"""Provide device store instance."""
|
||||
return DeviceStore(temp_storage)
|
||||
return DeviceStore(tmp_db)
|
||||
|
||||
|
||||
def test_device_creation():
|
||||
@@ -207,10 +210,11 @@ def test_device_exists(device_store):
|
||||
assert device_store.device_exists("nonexistent") is False
|
||||
|
||||
|
||||
def test_persistence(temp_storage):
|
||||
def test_persistence(tmp_path):
|
||||
"""Test device persistence across store instances."""
|
||||
db = Database(tmp_path / "persist.db")
|
||||
# Create store and add device
|
||||
store1 = DeviceStore(temp_storage)
|
||||
store1 = DeviceStore(db)
|
||||
device = store1.create_device(
|
||||
name="Test WLED",
|
||||
url="http://192.168.1.100",
|
||||
@@ -218,14 +222,15 @@ def test_persistence(temp_storage):
|
||||
)
|
||||
device_id = device.id
|
||||
|
||||
# Create new store instance (loads from file)
|
||||
store2 = DeviceStore(temp_storage)
|
||||
# Create new store instance (loads from database)
|
||||
store2 = DeviceStore(db)
|
||||
|
||||
# Verify device persisted
|
||||
loaded_device = store2.get_device(device_id)
|
||||
assert loaded_device is not None
|
||||
assert loaded_device.name == "Test WLED"
|
||||
assert loaded_device.led_count == 150
|
||||
db.close()
|
||||
|
||||
|
||||
def test_clear(device_store):
|
||||
|
||||
Reference in New Issue
Block a user