- Add pytest config with 90% coverage threshold - 15 test files covering all routers, services, schemas, models - 300 tests: unit tests, integration tests, edge cases, mocked external APIs - Update CI workflow to run pytest with coverage enforcement - Mock external services (Genius, MusicBrainz, RadioBrowser) - In-memory SQLite DB per test via conftest fixtures
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""Router tests - Search endpoints."""
|
|
from app.models.song import Song
|
|
from app.models.playlist import Playlist
|
|
|
|
|
|
class TestSearch:
|
|
def test_empty_search(self, client):
|
|
r = client.get("/api/search?q=test")
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert data["query"] == "test"
|
|
assert "songs" in data
|
|
assert "playlists" in data
|
|
assert "total_results" in data
|
|
|
|
def test_search_songs(self, client, db_module):
|
|
db = db_module.SessionLocal()
|
|
s = Song(id="s1", title="Hello World", artist="Test Artist", file_path="/tmp/t.mp3")
|
|
db.add(s)
|
|
db.commit()
|
|
db.close()
|
|
r = client.get("/api/search?q=Hello")
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert len(data["songs"]) >= 1
|
|
assert data["total_results"] >= 1
|
|
|
|
def test_search_playlists(self, client, db_module):
|
|
db = db_module.SessionLocal()
|
|
p = Playlist(id="p1", name="My Test Playlist")
|
|
db.add(p)
|
|
db.commit()
|
|
db.close()
|
|
r = client.get("/api/search?q=My+Test")
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert len(data["playlists"]) >= 1
|
|
|
|
def test_search_min_length(self, client):
|
|
r = client.get("/api/search?q=")
|
|
assert r.status_code == 422
|