71803418e5
Shelly device management app with mDNS/subnet discovery, inventory, configuration, and mass operations for Gen1/Gen2+ devices. Includes .gitignore excluding runtime data (device DB, user config), AI conversation history, build artifacts, and common Python/OS patterns.
39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
"""UI AppConfig persistence (Streamlit state module)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from unittest.mock import patch
|
|
|
|
from shelly_manager.core.config import AppConfig
|
|
|
|
|
|
def test_app_config_roundtrip_json(tmp_path: Path) -> None:
|
|
cfg = AppConfig(
|
|
subnet_scan_cidr="192.168.23.0/24",
|
|
discovery_http_timeout_sec=4.5,
|
|
sqlite_path=tmp_path / "db.sqlite",
|
|
markdown_dir=tmp_path / "md",
|
|
)
|
|
p = tmp_path / "ui.json"
|
|
p.write_text(cfg.model_dump_json(indent=2), encoding="utf-8")
|
|
loaded = AppConfig.model_validate_json(p.read_text(encoding="utf-8"))
|
|
assert loaded.subnet_scan_cidr == "192.168.23.0/24"
|
|
assert loaded.discovery_http_timeout_sec == 4.5
|
|
|
|
|
|
def test_persist_path_respects_env(tmp_path: Path) -> None:
|
|
target = tmp_path / "x" / "cfg.json"
|
|
with patch.dict(os.environ, {"SHELLY_UI_CONFIG": str(target)}, clear=False):
|
|
from shelly_manager.ui import state as state_mod
|
|
|
|
assert state_mod._persist_path() == target
|
|
|
|
|
|
def test_load_config_from_disk_returns_none_if_missing(tmp_path: Path) -> None:
|
|
with patch.dict(os.environ, {"SHELLY_UI_CONFIG": str(tmp_path / "nope.json")}, clear=False):
|
|
from shelly_manager.ui import state as state_mod
|
|
|
|
assert state_mod._load_config_from_disk() is None
|