111 lines
3.6 KiB
Python
111 lines
3.6 KiB
Python
import json
|
|
|
|
import respx
|
|
from fastapi.testclient import TestClient
|
|
from httpx import Response
|
|
|
|
from app.conf_store import config_path
|
|
from app.main import app
|
|
|
|
|
|
def configure_radarr(client: TestClient) -> None:
|
|
response = client.put(
|
|
"/api/settings/radarr",
|
|
json={"url": "http://radarr:7878", "api_key": "test-key"},
|
|
)
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_health() -> None:
|
|
with TestClient(app) as client:
|
|
response = client.get("/api/health")
|
|
assert response.status_code == 200
|
|
assert response.json()["database"] == "ok"
|
|
|
|
|
|
@respx.mock
|
|
def test_radarr_connection() -> None:
|
|
respx.get("http://radarr:7878/api/v3/system/status").mock(
|
|
return_value=Response(200, json={"version": "5.27.0"})
|
|
)
|
|
with TestClient(app) as client:
|
|
configure_radarr(client)
|
|
response = client.post("/api/settings/radarr/test")
|
|
assert response.status_code == 200
|
|
assert response.json()["version"] == "5.27.0"
|
|
|
|
|
|
@respx.mock
|
|
def test_scan_only_imports_iso_files() -> None:
|
|
respx.get("http://radarr:7878/api/v3/movie?includeMovieFile=true").mock(
|
|
return_value=Response(
|
|
200,
|
|
json=[
|
|
{
|
|
"id": 10,
|
|
"title": "ISO Movie",
|
|
"year": 2025,
|
|
"path": "/movies/ISO Movie (2025)",
|
|
"movieFile": {
|
|
"id": 20,
|
|
"relativePath": "ISO Movie (2025).iso",
|
|
"size": 42_000_000_000,
|
|
},
|
|
},
|
|
{
|
|
"id": 11,
|
|
"title": "MKV Movie",
|
|
"year": 2024,
|
|
"path": "/movies/MKV Movie (2024)",
|
|
"movieFile": {
|
|
"id": 21,
|
|
"relativePath": "MKV Movie (2024).mkv",
|
|
"size": 10_000_000_000,
|
|
},
|
|
},
|
|
],
|
|
)
|
|
)
|
|
with TestClient(app) as client:
|
|
configure_radarr(client)
|
|
scan = client.post("/api/scans")
|
|
movies = client.get("/api/movies")
|
|
assert scan.status_code == 200
|
|
assert scan.json()["iso_files"] == 1
|
|
assert [movie["title"] for movie in movies.json()] == ["ISO Movie"]
|
|
|
|
|
|
@respx.mock
|
|
def test_qbittorrent_connection() -> None:
|
|
respx.post("http://qbit:8080/api/v2/auth/login").mock(
|
|
return_value=Response(200, text="Ok.")
|
|
)
|
|
respx.get("http://qbit:8080/api/v2/app/version").mock(
|
|
return_value=Response(200, text="v5.0.2")
|
|
)
|
|
with TestClient(app) as client:
|
|
response = client.put(
|
|
"/api/settings/qbittorrent",
|
|
json={"url": "http://qbit:8080", "username": "admin", "password": "pass"},
|
|
)
|
|
assert response.status_code == 200
|
|
test = client.post("/api/settings/qbittorrent/test")
|
|
assert test.status_code == 200
|
|
assert test.json()["version"] == "v5.0.2"
|
|
|
|
|
|
def test_settings_persist_to_conf_json() -> None:
|
|
with TestClient(app) as client:
|
|
put = client.put(
|
|
"/api/settings/qbittorrent",
|
|
json={"url": "http://qbit:8080/", "username": "admin", "password": "pass"},
|
|
)
|
|
got = client.get("/api/settings/qbittorrent")
|
|
assert put.status_code == 200
|
|
assert put.json()["password_configured"] is True
|
|
assert got.json()["url"] == "http://qbit:8080"
|
|
raw = json.loads(config_path().read_text(encoding="utf-8"))
|
|
assert raw["qbittorrent"]["url"] == "http://qbit:8080"
|
|
assert raw["qbittorrent"]["username"] == "admin"
|
|
assert raw["qbittorrent"]["password"] == "pass"
|