def test_playlist_lookup_when_playlist_is_empty(session_mock, web_client_mock, caplog): web_client_mock.get_playlist.return_value = {} playlists._sp_links.clear() playlist = playlists.playlist_lookup(session_mock, web_client_mock, "nothing", None) assert playlist is None assert "Failed to lookup Spotify playlist URI 'nothing'" in caplog.text assert len(playlists._sp_links) == 0
def test_playlist_lookup_when_link_invalid(session_mock, web_client_mock, web_playlist_mock, caplog): session_mock.get_link.side_effect = ValueError("an error message") web_client_mock.get_playlist.return_value = web_playlist_mock playlists._sp_links.clear() playlist = playlists.playlist_lookup(session_mock, web_client_mock, "spotify:user:alice:playlist:foo", None) assert len(playlist.tracks) == 1 assert "Failed to get link 'spotify:track:abc'" in caplog.text
def test_playlist_lookup_when_not_logged_in( session_mock, web_client_mock, web_playlist_mock, connection_state ): web_client_mock.get_playlist.return_value = web_playlist_mock session_mock.connection.state = connection_state playlists._sp_links.clear() playlist = playlists.playlist_lookup( session_mock, web_client_mock, "spotify:user:alice:playlist:foo", None ) assert playlist.uri == "spotify:user:alice:playlist:foo" assert playlist.name == "Foo" assert len(playlists._sp_links) == 0
def test_playlist_lookup_stores_track_link( session_mock, web_client_mock, sp_track_mock, web_playlist_mock, web_track_mock, as_items, ): session_mock.get_link.return_value = sp_track_mock.link web_playlist_mock["tracks"]["items"] = [{"track": web_track_mock}] * 5 web_client_mock.get_playlist.return_value = web_playlist_mock playlists._sp_links.clear() playlists.playlist_lookup( session_mock, web_client_mock, "spotify:user:alice:playlist:foo", None, as_items, ) session_mock.get_link.assert_called_once_with("spotify:track:abc") assert {"spotify:track:abc": sp_track_mock.link} == playlists._sp_links
def _browse_playlist(session, web_client, uri, config): return playlists.playlist_lookup(session, web_client, uri, config["bitrate"], as_items=True)
def _lookup_playlist(config, session, web_client, uri): playlist = playlists.playlist_lookup(session, web_client, uri, config["bitrate"]) if playlist is None: raise spotify.Error("Playlist Web API lookup failed") return playlist.tracks