feat(config): add Pydantic AppConfig, BackupConfig, LoggingConfig; update tests and infra notes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
from src.server.models.config import (
|
||||
ConfigResponse,
|
||||
AppConfig,
|
||||
ConfigUpdate,
|
||||
LoggingConfig,
|
||||
SchedulerConfig,
|
||||
@@ -25,25 +25,31 @@ def test_logging_config_defaults_and_values():
|
||||
assert log.backup_count == 3
|
||||
|
||||
|
||||
def test_config_update_apply_to():
|
||||
base = ConfigResponse(
|
||||
scheduler=SchedulerConfig(),
|
||||
logging=LoggingConfig(),
|
||||
other={"a": 1},
|
||||
)
|
||||
def test_appconfig_and_config_update_apply_to():
|
||||
base = AppConfig()
|
||||
|
||||
upd = ConfigUpdate(scheduler=SchedulerConfig(enabled=False, interval_minutes=30))
|
||||
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["a"] == 1
|
||||
assert new2.other["b"] == 2
|
||||
assert new2.other.get("b") == 2
|
||||
|
||||
|
||||
def test_validation_result_model():
|
||||
vr = ValidationResult(valid=True)
|
||||
assert vr.valid is True
|
||||
assert isinstance(vr.errors, list)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user