Add settings connection tests
This commit is contained in:
@@ -46,6 +46,9 @@ def test_index_renders_settings_dialog(tmp_path, monkeypatch):
|
||||
assert "SABnzbd" in response.text
|
||||
assert "Radarr" in response.text
|
||||
assert "Sonarr" in response.text
|
||||
assert "Test SABnzbd connection" in response.text
|
||||
assert "Test Radarr connection" in response.text
|
||||
assert "Test Sonarr connection" in response.text
|
||||
|
||||
|
||||
def test_settings_endpoint_persists_arr_connection_values(tmp_path, monkeypatch):
|
||||
@@ -77,3 +80,37 @@ def test_settings_endpoint_persists_arr_connection_values(tmp_path, monkeypatch)
|
||||
}
|
||||
assert main.settings.sab_api_key == "sab-secret"
|
||||
assert main.state.get_app_state("radarr_api_key") == "radarr-secret"
|
||||
|
||||
|
||||
def test_sab_connection_test_reports_success(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("IMPORTARR_STATE_PATH", str(tmp_path / "state.db"))
|
||||
import importarr.main as main
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
async def fake_queue(self):
|
||||
return {"queue": {"slots": [{"name": "one"}, {"name": "two"}]}}
|
||||
|
||||
monkeypatch.setattr(main.SabnzbdClient, "queue", fake_queue)
|
||||
|
||||
response = TestClient(main.app).post(
|
||||
"/api/settings/test-connection",
|
||||
json={"service": "sabnzbd", "url": "http://sab:8080", "api_key": "secret"},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"ok": True, "service": "sabnzbd", "message": "Connected to SABnzbd; 2 queued jobs visible."}
|
||||
|
||||
|
||||
def test_connection_test_rejects_unknown_service(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("IMPORTARR_STATE_PATH", str(tmp_path / "state.db"))
|
||||
import importarr.main as main
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
response = TestClient(main.app).post(
|
||||
"/api/settings/test-connection",
|
||||
json={"service": "lidarr", "url": "http://lidarr:8686"},
|
||||
)
|
||||
|
||||
assert response.status_code == 400
|
||||
|
||||
Reference in New Issue
Block a user