56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
import pytest
|
|
|
|
from src.server.models.config import (
|
|
AppConfig,
|
|
ConfigUpdate,
|
|
LoggingConfig,
|
|
SchedulerConfig,
|
|
ValidationResult,
|
|
)
|
|
|
|
|
|
def test_scheduler_defaults_and_validation():
|
|
sched = SchedulerConfig()
|
|
assert sched.enabled is True
|
|
assert sched.interval_minutes == 60
|
|
|
|
with pytest.raises(ValueError):
|
|
SchedulerConfig(interval_minutes=0)
|
|
|
|
|
|
def test_logging_config_defaults_and_values():
|
|
log = LoggingConfig()
|
|
assert log.level == "INFO"
|
|
assert log.file is None
|
|
assert log.backup_count == 3
|
|
|
|
|
|
def test_appconfig_and_config_update_apply_to():
|
|
base = AppConfig()
|
|
|
|
upd = ConfigUpdate(
|
|
scheduler=SchedulerConfig(enabled=False, interval_minutes=30)
|
|
)
|
|
new = upd.apply_to(base)
|
|
assert isinstance(new, AppConfig)
|
|
assert new.scheduler.enabled is False
|
|
assert new.scheduler.interval_minutes == 30
|
|
|
|
upd2 = ConfigUpdate(other={"b": 2})
|
|
new2 = upd2.apply_to(base)
|
|
assert new2.other.get("b") == 2
|
|
|
|
|
|
def test_backup_and_validation():
|
|
cfg = AppConfig()
|
|
# default backups disabled -> valid
|
|
res: ValidationResult = cfg.validate()
|
|
assert res.valid is True
|
|
|
|
# enable backups but leave path empty -> invalid
|
|
cfg.backup.enabled = True
|
|
cfg.backup.path = ""
|
|
res2 = cfg.validate()
|
|
assert res2.valid is False
|
|
assert any("backup.path" in e for e in res2.errors)
|