Files
ledgrab/server/tests/test_config.py
T
alexei.dolgolyov 02cd9d519c
Lint & Test / test (push) Successful in 1m56s
refactor: rename project to LedGrab, split HA integration into separate repo
- Rename Python package: wled_controller -> ledgrab
- Rename env var prefix: WLED_ -> LEDGRAB_ (with auto-migration for old vars)
- Rename localStorage key: wled_api_key -> ledgrab_api_key (with migration)
- Rename HA integration domain: wled_screen_controller -> ledgrab
- Update all imports, build scripts, Docker, installer, config, docs
- Remove HA integration (moved to ledgrab-haos-integration repo)
- Remove hacs.json (belongs in HA repo now)
- Add startup warning for users with old WLED_ env vars
- All tests pass (715/715), ruff clean, tsc clean, frontend builds
2026-04-12 22:45:28 +03:00

89 lines
2.5 KiB
Python

"""Tests for configuration management."""
import pytest
import yaml
from ledgrab.config import (
Config,
ServerConfig,
get_config,
reload_config,
)
class TestDefaultConfig:
def test_default_server_values(self):
config = Config()
assert config.server.host == "0.0.0.0"
assert config.server.port == 8080
assert config.server.log_level == "INFO"
def test_default_storage_paths(self):
config = Config()
assert config.storage.database_file == "data/ledgrab.db"
def test_default_mqtt_disabled(self):
config = Config()
assert config.mqtt.enabled is False
def test_default_demo_off(self):
config = Config()
assert config.demo is False
class TestFromYaml:
def test_load_from_yaml(self, tmp_path):
config_data = {
"server": {"host": "127.0.0.1", "port": 9000},
"auth": {"api_keys": {"dev": "secret"}},
}
config_path = tmp_path / "test_config.yaml"
with open(config_path, "w") as f:
yaml.dump(config_data, f)
config = Config.from_yaml(config_path)
assert config.server.host == "127.0.0.1"
assert config.server.port == 9000
assert config.auth.api_keys == {"dev": "secret"}
def test_load_from_yaml_file_not_found(self):
with pytest.raises(FileNotFoundError):
Config.from_yaml("nonexistent.yaml")
class TestEnvironmentVariables:
def test_env_overrides(self, monkeypatch):
monkeypatch.setenv("LEDGRAB_SERVER__HOST", "192.168.1.1")
monkeypatch.setenv("LEDGRAB_SERVER__PORT", "7000")
config = Config()
assert config.server.host == "192.168.1.1"
assert config.server.port == 7000
class TestServerConfig:
def test_creation(self):
sc = ServerConfig(host="localhost", port=8000)
assert sc.host == "localhost"
assert sc.port == 8000
assert sc.log_level == "INFO"
class TestDemoMode:
def test_demo_rewrites_storage_paths(self):
config = Config(demo=True)
assert config.storage.database_file.startswith("data/demo/")
def test_non_demo_keeps_original_paths(self):
config = Config(demo=False)
assert config.storage.database_file == "data/ledgrab.db"
class TestGlobalConfig:
def test_get_config_returns_config(self):
config = get_config()
assert isinstance(config, Config)
def test_reload_config_returns_new_config(self):
config = reload_config()
assert isinstance(config, Config)