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

42 lines
1.2 KiB
Python

from fastapi.testclient import TestClient
from app.main import app
c = TestClient(app)
def test_search_rejects_empty_query():
r = c.get("/api/search", params={"type": "track", "q": ""})
assert r.status_code == 400
def test_search_rejects_invalid_type():
r = c.get("/api/search", params={"type": "foo", "q": "x"})
assert r.status_code == 422
def test_search_track_mocked(monkeypatch):
from app.services import streamrip_service as svc
async def fake_search(media_type, query, limit):
assert media_type == "track"
return [
{
"source": "deezer",
"media_type": "track",
"id": "123",
"title": "Test Song",
"artist": "Test Artist",
"desc": "Test Song by Test Artist",
"cover": None,
"preview_url": None,
"duration": None,
}
]
monkeypatch.setattr(svc, "search_deezer", fake_search)
r = c.get("/api/search", params={"type": "track", "q": "test"})
assert r.status_code == 200
body = r.json()
assert body["results"][0]["id"] == "123"
assert body["results"][0]["title"] == "Test Song"