Files
streamrip-ui/backend/tests/test_batch.py
T

41 lines
1.1 KiB
Python

from fastapi.testclient import TestClient
from app.main import app
c = TestClient(app)
def test_batch_mixed_valid_invalid(monkeypatch):
from app.api import downloads as dl
seen = []
async def fake_enqueue(params):
seen.append(params)
return {"job_id": f"job-{len(seen)}", "status": "queued"}
monkeypatch.setattr(dl, "enqueue_download", fake_enqueue)
r = c.post(
"/api/downloads/batch",
json={
"items": [
{"media_type": "track", "id": "111"},
{"media_type": "nope", "id": "x"},
{"media_type": "album", "id": ""},
{"url": "https://www.deezer.com/album/302127"},
{"url": "https://example.com/nope"},
]
},
)
assert r.status_code == 200
body = r.json()
assert len(body["job_ids"]) == 2
assert len(body["rejected"]) == 3
def test_batch_limit():
r = c.post(
"/api/downloads/batch",
json={"items": [{"media_type": "track", "id": str(i)} for i in range(60)]},
)
assert r.status_code == 422