def test_get_authorize_url_shows_dialog_when_requested(self): auth = SpotifyImplicitGrant("CLID", "REDIR", show_dialog=True) url = auth.get_authorize_url() parsed_url = urllibparse.urlparse(url) parsed_qs = urllibparse.parse_qs(parsed_url.query) self.assertTrue(parsed_qs['show_dialog'])
def test_get_authorize_url_does_not_show_dialog_by_default(self): auth = SpotifyImplicitGrant("CLID", "REDIR") url = auth.get_authorize_url() parsed_url = urllibparse.urlparse(url) parsed_qs = urllibparse.parse_qs(parsed_url.query) self.assertNotIn('show_dialog', parsed_qs)
def test_get_authorize_url_passes_state_from_func_call(self): state = "STATE" auth = SpotifyImplicitGrant("CLID", "REDIR", "NOT STATE") url = auth.get_authorize_url(state=state) parsed_url = urllibparse.urlparse(url) parsed_qs = urllibparse.parse_qs(parsed_url.query) self.assertEqual(parsed_qs['state'][0], state)
def test_saves_to_cache_path(self, opener): scope = "playlist-modify-private" path = ".cache-username" tok = _make_fake_token(1, 1, scope) fi = _fake_file() opener.return_value = fi spot = SpotifyImplicitGrant("CLID", "REDIR", "STATE", scope, path) spot._save_token_info(tok) opener.assert_called_with(path, 'w') self.assertTrue(fi.write.called)
def setUpClass(cls): scope = ( 'user-follow-read ' 'user-follow-modify ' ) auth_manager = SpotifyImplicitGrant(scope=scope, cache_path=".cache-implicittest") cls.spotify = Spotify(auth_manager=auth_manager)
def _make_implicitgrantauth(*args, **kwargs): return SpotifyImplicitGrant("CLID", "REDIR", "STATE", *args, **kwargs)
from models.track import Track from utils.common import clear_string, chunk SPOTIFY_REDIRECT_URL = 'http://localhost/' scope = ','.join([ 'playlist-read-collaborative', 'playlist-modify-public', 'playlist-read-private', 'playlist-modify-private', ]) sp = spotipy.Spotify(auth_manager=SpotifyImplicitGrant( client_id='f7c529d9b38b465891d8ba2a95ce7b18', redirect_uri=SPOTIFY_REDIRECT_URL, cache_path='./.spotify-cache', )) def get_playlist_id(name: str) -> Optional[str]: offset = 0 while True: response = sp.current_user_playlists(50, offset) total = response.get('total') items = response.get('items') offset += len(items) for item in items: if item.get('name') == name: