74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
import respx
|
|
from fastapi.testclient import TestClient
|
|
from httpx import Response
|
|
|
|
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").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"]
|
|
|