Aniworld/tests/api/test_config_endpoints.py

37 lines
1007 B
Python

from fastapi.testclient import TestClient
from src.server.fastapi_app import app
from src.server.models.config import AppConfig, SchedulerConfig
client = TestClient(app)
def test_get_config_public():
resp = client.get("/api/config")
assert resp.status_code == 200
data = resp.json()
assert "name" in data
assert "data_dir" in data
def test_validate_config():
cfg = {
"name": "Aniworld",
"data_dir": "data",
"scheduler": {"enabled": True, "interval_minutes": 30},
"logging": {"level": "INFO"},
"backup": {"enabled": False},
"other": {},
}
resp = client.post("/api/config/validate", json=cfg)
assert resp.status_code == 200
body = resp.json()
assert body.get("valid") is True
def test_update_config_unauthorized():
# update requires auth; without auth should be 401
update = {"scheduler": {"enabled": False}}
resp = client.put("/api/config", json=update)
assert resp.status_code in (401, 422)