44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.core import settings
|
|
|
|
|
|
@pytest.fixture
|
|
def tmp_config(tmp_path, monkeypatch):
|
|
cfg = tmp_path / "config.toml"
|
|
cfg.write_text('[deezer]\narl = "old-arl-value"\nquality = 1\n')
|
|
monkeypatch.setattr(settings, "CONFIG_PATH", str(cfg))
|
|
return cfg
|
|
|
|
|
|
def test_arl_get_masked(tmp_config):
|
|
from app.main import app
|
|
|
|
c = TestClient(app)
|
|
r = c.get("/api/config/arl")
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert body["arl_set"] is True
|
|
assert "old-arl-value" not in body["arl_preview"]
|
|
assert body["arl_preview"].endswith("alue")
|
|
|
|
|
|
def test_arl_put_updates_only_arl(tmp_config):
|
|
from app.main import app
|
|
|
|
c = TestClient(app)
|
|
r = c.put("/api/config/arl", json={"arl": "new-arl-123"})
|
|
assert r.status_code == 200
|
|
text = tmp_config.read_text()
|
|
assert "new-arl-123" in text
|
|
assert "quality = 1" in text # rest untouched
|
|
assert tmp_config.with_suffix(".toml.bak").exists()
|
|
|
|
|
|
def test_arl_put_rejects_empty(tmp_config):
|
|
from app.main import app
|
|
|
|
c = TestClient(app)
|
|
assert c.put("/api/config/arl", json={"arl": " "}).status_code == 422
|