feat: device model, API, static UI, and endpoint tests

Made-with: Cursor
This commit is contained in:
2026-03-21 20:17:33 +13:00
parent 13538c39a6
commit a75e27e3d2
7 changed files with 441 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ from test_group import test_group
from test_sequence import test_sequence
from test_tab import test_tab
from test_palette import test_palette
from test_device import test_device
def run_all_tests():
"""Run all model tests."""
@@ -27,6 +28,7 @@ def run_all_tests():
("Sequence", test_sequence),
("Tab", test_tab),
("Palette", test_palette),
("Device", test_device),
]
passed = 0

View File

@@ -0,0 +1,64 @@
from models.device import Device
import os
def test_device():
"""Test Device model CRUD operations."""
db_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "db")
device_file = os.path.join(db_dir, "device.json")
if os.path.exists(device_file):
os.remove(device_file)
devices = Device()
print("Testing create device")
device_id = devices.create("Test Device", address="aa:bb:cc:dd:ee:ff", default_pattern="on", tabs=["1", "2"])
print(f"Created device with ID: {device_id}")
assert device_id is not None
assert device_id in devices
print("\nTesting read device")
device = devices.read(device_id)
print(f"Read: {device}")
assert device is not None
assert device["name"] == "Test Device"
assert device["address"] == "aabbccddeeff"
assert device["default_pattern"] == "on"
assert device["tabs"] == ["1", "2"]
print("\nTesting address normalization")
devices.update(device_id, {"address": "11:22:33:44:55:66"})
updated = devices.read(device_id)
assert updated["address"] == "112233445566"
print("\nTesting update device")
update_data = {
"name": "Updated Device",
"default_pattern": "rainbow",
"tabs": ["1", "2", "3"],
}
result = devices.update(device_id, update_data)
assert result is True
updated = devices.read(device_id)
assert updated["name"] == "Updated Device"
assert updated["default_pattern"] == "rainbow"
assert len(updated["tabs"]) == 3
print("\nTesting list devices")
device_list = devices.list()
print(f"Device list: {device_list}")
assert device_id in device_list
print("\nTesting delete device")
deleted = devices.delete(device_id)
assert deleted is True
assert device_id not in devices
print("\nTesting read after delete")
device = devices.read(device_id)
assert device is None
print("\nAll device tests passed!")
if __name__ == "__main__":
test_device()