async def test_describe_added_tracks_and_albums(self, playlist, album, track): album_tracks = AlbumTracks(parent=album, tracks=[track, track, track]) stats = SpotifyStats( "test-id", playlist, { "tracks": [album_tracks], "albums": [album_tracks], "singles": [] }, ) expected = [ "Playlist: Test Playlist", "", "-== Albums ==-", "Test Artist - Test Album", "", "-== Tracks ==-", "Test Artist - Test Album", "", "Link: https://open.spotify.com/playlist/test_playlist", ] output = stats.describe() for line1, line2 in zip(output.splitlines(), expected): assert line1 == line2
async def _get_album_tracks(sp: Spotter, item: Album, is_album: bool) -> AlbumTracks: if is_album: album = await _make_album_tracks(sp, item) else: track = await sp.client.track(item.uri) album = AlbumTracks(track["album"], [track]) return album
def _clean_update_playlist_already_present( album: AlbumTracks, already_present_tracks: set) -> Tuple[AlbumTracks, set]: """helper method to clean up already present items from playlist and update it""" album.tracks = [ a for a in album.tracks if a["name"] not in already_present_tracks ] # update list with new ids __update_already_present(already_present_tracks, album) return album, already_present_tracks
async def test_humanize_track(self, track): noalbum_tracks = AlbumTracks(parent=None, tracks=[track]) assert (SpotifyStats.humanize_track( noalbum_tracks.tracks[0]) == "Test Artist - Test Track")
async def _make_album_tracks(sp: Spotter, album: Album) -> AlbumTracks: tracks = [] # type: List[dict] album_data = await sp.client.album(album.uri) tracks = await fetch_all(sp, album_data["tracks"]) return AlbumTracks(album_data, tracks)