music-app/backend/tests/test_routers_search.py
Jarian Cottingham 24c03426f8 test: add comprehensive test suite with 94% coverage
- 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
2026-07-06 06:07:31 +00:00

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