- 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
63 lines
1.9 KiB
Python
63 lines
1.9 KiB
Python
"""Router tests - Events, Releases, Account endpoints."""
|
|
from app.models.song import Song
|
|
from app.models.playlist import Playlist
|
|
|
|
|
|
class TestEvents:
|
|
def test_list_events(self, client):
|
|
r = client.get("/api/events")
|
|
assert r.status_code == 200
|
|
events = r.json()
|
|
assert len(events) >= 3
|
|
assert all("name" in e for e in events)
|
|
|
|
def test_list_with_location(self, client):
|
|
r = client.get("/api/events?lat=40.7&lon=-74.0")
|
|
assert r.status_code == 200
|
|
|
|
|
|
class TestReleases:
|
|
def test_check_releases(self, client):
|
|
r = client.get("/api/releases")
|
|
assert r.status_code == 200
|
|
|
|
def test_check_artist(self, client):
|
|
r = client.get("/api/releases?artist=TestArtist")
|
|
assert r.status_code == 200
|
|
|
|
def test_check_artist_specific(self, client):
|
|
r = client.get("/api/releases/TestArtist")
|
|
assert r.status_code == 200
|
|
|
|
|
|
class TestAccount:
|
|
def test_stats(self, client):
|
|
r = client.get("/api/account/stats")
|
|
assert r.status_code == 200
|
|
data = r.json()
|
|
assert "total_songs" in data
|
|
assert "total_playlists" in data
|
|
assert "top_artists" in data
|
|
assert "top_genres" in data
|
|
assert "top_moods" in data
|
|
|
|
def test_stats_with_data(self, client, db_module):
|
|
db = db_module.SessionLocal()
|
|
s1 = Song(id="s1", title="T1", artist="A1", file_path="/tmp/1.mp3")
|
|
s2 = Song(id="s2", title="T2", artist="A1", file_path="/tmp/2.mp3")
|
|
p = Playlist(id="p1", name="Test")
|
|
db.add(s1)
|
|
db.add(s2)
|
|
db.add(p)
|
|
db.commit()
|
|
db.close()
|
|
r = client.get("/api/account/stats")
|
|
assert r.status_code == 200
|
|
assert r.json()["total_songs"] == 2
|
|
assert r.json()["total_playlists"] == 1
|
|
|
|
def test_history(self, client):
|
|
r = client.get("/api/account/history")
|
|
assert r.status_code == 200
|
|
assert r.json() == []
|