Phase 1 (Foundation): project skeleton, TOML config + Pydantic validation, MQTT bus wrapper, SQLite schema (9 tables), Click CLI, process supervisor. Phase 2 (Camera): RTSP capture via OpenCV, MOG2 motion detection with configurable sensitivity/zones, adaptive FPS recording (2fps idle/30fps motion) via FFmpeg subprocess, HLS live streaming, pre-motion ring buffer. Phase 3 (Web UI): Flask + Bootstrap 5 dark theme, 6 blueprints, Jinja2 templates (dashboard, kiosk 2x2 grid, events, sensors, recordings, settings), PWA with service worker + Web Push, full admin settings UI with config persistence. Remote Access: WireGuard tunnel configs, nginx reverse proxy with HLS caching + rate limiting, bandwidth-optimized remote HLS stream (426x240 @ 500kbps), DO droplet setup script, certbot TLS. 29 tests passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
63 lines
1.6 KiB
Python
63 lines
1.6 KiB
Python
"""Tests for config writer."""
|
|
|
|
import tomllib
|
|
from pathlib import Path
|
|
|
|
from vigilar.config import CameraConfig, VigilarConfig
|
|
from vigilar.config_writer import (
|
|
save_config,
|
|
update_camera_config,
|
|
update_config_section,
|
|
)
|
|
|
|
|
|
def test_update_config_section():
|
|
cfg = VigilarConfig()
|
|
assert cfg.system.timezone == "UTC"
|
|
|
|
new_cfg = update_config_section(cfg, "system", {"timezone": "America/New_York"})
|
|
assert new_cfg.system.timezone == "America/New_York"
|
|
# Original unchanged
|
|
assert cfg.system.timezone == "UTC"
|
|
|
|
|
|
def test_update_camera_config():
|
|
cfg = VigilarConfig(cameras=[
|
|
CameraConfig(id="cam1", display_name="Cam 1", rtsp_url="rtsp://a"),
|
|
])
|
|
assert cfg.cameras[0].motion_sensitivity == 0.7
|
|
|
|
new_cfg = update_camera_config(cfg, "cam1", {"motion_sensitivity": 0.9})
|
|
assert new_cfg.cameras[0].motion_sensitivity == 0.9
|
|
|
|
|
|
def test_save_and_reload(tmp_path):
|
|
cfg = VigilarConfig(cameras=[
|
|
CameraConfig(id="test", display_name="Test Cam", rtsp_url="rtsp://localhost"),
|
|
])
|
|
|
|
path = tmp_path / "test.toml"
|
|
save_config(cfg, path)
|
|
|
|
assert path.exists()
|
|
with open(path, "rb") as f:
|
|
data = tomllib.load(f)
|
|
|
|
assert data["system"]["name"] == "Vigilar Home Security"
|
|
assert len(data["cameras"]) == 1
|
|
assert data["cameras"][0]["id"] == "test"
|
|
|
|
|
|
def test_save_creates_backup(tmp_path):
|
|
path = tmp_path / "test.toml"
|
|
cfg = VigilarConfig()
|
|
|
|
# First save
|
|
save_config(cfg, path)
|
|
assert path.exists()
|
|
|
|
# Second save should create backup
|
|
save_config(cfg, path)
|
|
backups = list(tmp_path.glob("*.bak.*"))
|
|
assert len(backups) == 1
|