def test_add(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) playlist.tofile() SongFactory(name='Ασδφ', artist='Ασδφ').tofile() playlist.add('asdf') assert (playlist.directory / f'{playlist.slug}.yml').read_text() == dedent("""\ name: Λίστα songs: - name: Ασδφ slug: asdf artist: Ασδφ artist_slug: asdf - name: Νέημ slug: neim artist: Βαμβακάρης artist_slug: vamvakaris root: A - name: Τεστ slug: test artist: Βαμβακάρης artist_slug: vamvakaris """)
def test_all(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) playlist.tofile() assert Playlist.all() == [playlist]
def test_add_invalid_root(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) playlist.tofile() SongFactory(name='Ασδφ', artist='Ασδφ').tofile() with pytest.raises(InvalidNote): playlist.add('asdf', root='L')
def test_contains(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) playlist.tofile() assert 'test' in playlist assert SongFactory(name='Τεστ') in playlist assert 'asdf' not in playlist assert SongFactory(name='Ασδφ') not in playlist
def test_init(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) assert playlist.name == 'Λίστα' assert playlist.slug == 'lista' assert playlist.songs == songs assert playlist.num == 2
def get(cls, slug): """Playlist constructor that takes the name of the scale.""" path: Path = app.config['DIR'] / 'playlists' / f'{slug}.yml' try: data = yaml.safe_load(path.read_text()) except FileNotFoundError: raise DoesNotExist(f"Playlist '{slug}' does not exist") songs = [] roots = {} for song_data in data['songs']: songs.append(Song.frommetadata(song_data)) if 'root' in song_data: roots[song_data['slug']] = song_data['root'] return cls(name=data['name'], songs=songs, roots=roots)
def test_remove(client): songs = [ Song.frommetadata(song_data) for song_data in playlist_data['songs'] ] playlist = Playlist(name=playlist_data['name'], songs=songs) playlist.tofile() playlist.remove('neim') assert (playlist.directory / f'{playlist.slug}.yml').read_text() == dedent("""\ name: Λίστα songs: - name: Τεστ slug: test artist: Βαμβακάρης artist_slug: vamvakaris """)