Aniworld/tests/unit/test_config_models.py
Lukas 3cb644add4 fix: resolve pylint and type-checking issues
- Fix return type annotation in SetupRedirectMiddleware.dispatch() to use Response instead of RedirectResponse
- Replace broad 'except Exception' with specific exception types (FileNotFoundError, ValueError, OSError, etc.)
- Rename AppConfig.validate() to validate_config() to avoid shadowing BaseModel.validate()
- Fix ValidationResult.errors field to use List[str] with default_factory
- Add pylint disable comments for intentional broad exception catches during shutdown
- Rename lifespan parameter to _application to indicate unused variable
- Update all callers to use new validate_config() method name
2025-12-13 20:29:07 +01:00

56 lines
1.4 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_config()
assert res.valid is True
# enable backups but leave path empty -> invalid
cfg.backup.enabled = True
cfg.backup.path = ""
res2 = cfg.validate_config()
assert res2.valid is False
assert any("backup.path" in e for e in res2.errors)