music-app/backend/tests/test_routers_mood.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

71 lines
2.2 KiB
Python

"""Router tests - Mood endpoints."""
from app.models.song import Song
from app.models.settings import UserSetting
class TestMoodCategories:
def test_list_categories(self, client):
r = client.get("/api/mood/categories")
assert r.status_code == 200
data = r.json()
assert len(data) == 10
names = [c["name"] for c in data]
assert "Sad" in names
assert "Happy" in names
assert all("color_hex" in c for c in data)
class TestMoodPlaylist:
def test_get_playlist(self, client):
r = client.get("/api/mood/Happy/playlist")
assert r.status_code == 200
data = r.json()
assert data["mood"] == "Happy"
assert "songs" in data
assert "total_songs" in data
class TestSetMood:
def test_set_mood(self, client):
r = client.post("/api/mood/set", json={"mood": "Chill"})
assert r.status_code == 200
assert r.json()["mood"] == "Chill"
def test_set_mood_persists(self, client, db_module):
client.post("/api/mood/set", json={"mood": "Energetic"})
db = db_module.SessionLocal()
s = db.query(UserSetting).filter(UserSetting.key == "default_mood").first()
assert s is not None
assert s.value == "Energetic"
db.close()
class TestAnalyzeMood:
def test_analyze_all(self, client):
r = client.post("/api/mood/analyze")
assert r.status_code == 200
data = r.json()
assert "analyzed" in data
assert "results" in data
assert data["analyzed"] == 0
def test_analyze_specific(self, client, db_module):
db = db_module.SessionLocal()
song = Song(id="s1", title="Test", artist="A", file_path="/tmp/t.mp3")
db.add(song)
db.commit()
db.close()
r = client.post("/api/mood/analyze", params={"song_id": "s1"})
assert r.status_code == 200
assert "song_id" in r.json()
class TestSaveMoodPlaylist:
def test_save(self, client):
r = client.post("/api/mood/save", params={"mood": "Happy", "name": "My Happy"})
assert r.status_code == 200
data = r.json()
assert data["name"] == "My Happy"
assert "id" in data
assert "songs" in data