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

31 lines
834 B
Python

from fastapi.testclient import TestClient
from app.main import app
c = TestClient(app)
def test_create_download_validation():
r = c.post("/api/downloads", json={"media_type": "nope", "id": "x"})
assert r.status_code == 422
def test_create_download_queued(monkeypatch):
from app.api import downloads as dl
async def fake_enqueue(params):
return {"job_id": "test-id", "status": "queued"}
monkeypatch.setattr(dl, "enqueue_download", fake_enqueue)
r = c.post(
"/api/downloads",
json={"media_type": "track", "id": "123", "quality": 2},
)
assert r.status_code == 200
assert r.json()["job_id"] == "test-id"
def test_unknown_job_sse_404():
r = c.get("/api/downloads/does-not-exist/events")
# SSE endpoint must not hang on unknown id
assert r.status_code == 404