50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
import pytest
|
|
|
|
from src.server.models.config import (
|
|
ConfigResponse,
|
|
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_config_update_apply_to():
|
|
base = ConfigResponse(
|
|
scheduler=SchedulerConfig(),
|
|
logging=LoggingConfig(),
|
|
other={"a": 1},
|
|
)
|
|
|
|
upd = ConfigUpdate(scheduler=SchedulerConfig(enabled=False, interval_minutes=30))
|
|
new = upd.apply_to(base)
|
|
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
|
|
|
|
|
|
def test_validation_result_model():
|
|
vr = ValidationResult(valid=True)
|
|
assert vr.valid is True
|
|
assert isinstance(vr.errors, list)
|