- 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
113 lines
3.7 KiB
Python
113 lines
3.7 KiB
Python
"""Model tests - SQLAlchemy ORM models."""
|
|
|
|
|
|
class TestSongModel:
|
|
def test_table_name(self):
|
|
from app.models.song import Song
|
|
assert Song.__tablename__ == "songs"
|
|
|
|
def test_create_song(self):
|
|
from app.models.song import Song
|
|
s = Song(id="1", title="Test", artist="A", file_path="/tmp/t.mp3")
|
|
assert s.id == "1"
|
|
assert s.title == "Test"
|
|
assert s.artist == "A"
|
|
|
|
|
|
class TestPlaylistModel:
|
|
def test_table_name(self):
|
|
from app.models.playlist import Playlist, PlaylistSong
|
|
assert Playlist.__tablename__ == "playlists"
|
|
assert PlaylistSong.__tablename__ == "playlist_songs"
|
|
|
|
def test_create_playlist(self):
|
|
from app.models.playlist import Playlist
|
|
p = Playlist(id="1", name="Test")
|
|
assert p.name == "Test"
|
|
|
|
|
|
class TestMoodModels:
|
|
def test_table_names(self):
|
|
from app.models.mood import MoodCategory, MoodSong, LyricsCache
|
|
assert MoodCategory.__tablename__ == "mood_categories"
|
|
assert MoodSong.__tablename__ == "mood_songs"
|
|
assert LyricsCache.__tablename__ == "lyrics_cache"
|
|
|
|
def test_mood_category(self):
|
|
from app.models.mood import MoodCategory
|
|
mc = MoodCategory(id="sad", name="Sad", color_hex="#1a2a4a")
|
|
assert mc.id == "sad"
|
|
|
|
def test_mood_song(self):
|
|
from app.models.mood import MoodSong
|
|
ms = MoodSong(mood_id="happy", song_id="s1", confidence_score=0.9)
|
|
assert ms.confidence_score == 0.9
|
|
|
|
|
|
class TestLofiModel:
|
|
def test_table_name(self):
|
|
from app.models.lofi import LofiChannel
|
|
assert LofiChannel.__tablename__ == "lofi_channels"
|
|
|
|
def test_create_channel(self):
|
|
from app.models.lofi import LofiChannel
|
|
lc = LofiChannel(id="1", name="Lofi", stream_url="https://s.com")
|
|
assert lc.name == "Lofi"
|
|
assert lc.stream_url == "https://s.com"
|
|
|
|
|
|
class TestRadioModel:
|
|
def test_table_name(self):
|
|
from app.models.radio import RadioStation
|
|
assert RadioStation.__tablename__ == "radio_stations"
|
|
|
|
def test_create_station(self):
|
|
from app.models.radio import RadioStation
|
|
rs = RadioStation(id="1", name="Test", stream_url="https://s.com")
|
|
assert rs.name == "Test"
|
|
|
|
|
|
class TestShareplayModels:
|
|
def test_table_names(self):
|
|
from app.models.shareplay import SharePlayRoom, SharePlayCue
|
|
assert SharePlayRoom.__tablename__ == "shareplay_rooms"
|
|
assert SharePlayCue.__tablename__ == "shareplay_cue"
|
|
|
|
def test_room_defaults(self):
|
|
from app.models.shareplay import SharePlayRoom
|
|
r = SharePlayRoom(id="1", creator_user="u1")
|
|
assert r.creator_user == "u1"
|
|
|
|
|
|
class TestSettingsModel:
|
|
def test_table_name(self):
|
|
from app.models.settings import UserSetting
|
|
assert UserSetting.__tablename__ == "user_settings"
|
|
|
|
def test_create_setting(self):
|
|
from app.models.settings import UserSetting
|
|
s = UserSetting(key="theme", value="dark")
|
|
assert s.key == "theme"
|
|
|
|
|
|
class TestEventsModel:
|
|
def test_table_name(self):
|
|
from app.models.events import ConcertEvent
|
|
assert ConcertEvent.__tablename__ == "concert_events"
|
|
|
|
def test_create_event(self):
|
|
from app.models.events import ConcertEvent
|
|
e = ConcertEvent(id="1", name="Test", date="2025-01-01")
|
|
assert e.name == "Test"
|
|
|
|
|
|
class TestReleasesModel:
|
|
def test_table_name(self):
|
|
from app.models.releases import NewReleaseCheck
|
|
assert NewReleaseCheck.__tablename__ == "new_releases_check"
|
|
|
|
def test_create_check(self):
|
|
from app.models.releases import NewReleaseCheck
|
|
nrc = NewReleaseCheck(id="1", artist_name="Artist")
|
|
assert nrc.artist_name == "Artist"
|