31 lines
862 B
Python
31 lines
862 B
Python
from fastapi.testclient import TestClient
|
|
from app.main import app
|
|
|
|
c = TestClient(app)
|
|
|
|
|
|
def test_url_import_rejects_garbage():
|
|
r = c.post("/api/downloads", json={"url": "not a url"})
|
|
assert r.status_code == 422
|
|
|
|
|
|
def test_url_import_rejects_wrong_host():
|
|
r = c.post("/api/downloads", json={"url": "https://example.com/foo"})
|
|
assert r.status_code == 422
|
|
|
|
|
|
def test_url_import_queued(monkeypatch):
|
|
from app.api import downloads as dl
|
|
|
|
async def fake_enqueue(params):
|
|
assert params["url"].startswith("https://www.deezer.com/")
|
|
return {"job_id": "url-job", "status": "queued"}
|
|
|
|
monkeypatch.setattr(dl, "enqueue_download", fake_enqueue)
|
|
r = c.post(
|
|
"/api/downloads",
|
|
json={"url": "https://www.deezer.com/album/302127"},
|
|
)
|
|
assert r.status_code == 200
|
|
assert r.json()["job_id"] == "url-job"
|