Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_specifying_pos_args_until_limit(self, app_token):
client = Spotify(app_token, max_limits_on=True)
s1, = client.search('piano', ('track',), None, None)
with client.max_limits(False):
s2, = client.search('piano', ('track',), None, None)
assert s1.limit > s2.limit
def test_specifying_limit_pos_arg_overrides_max_limits(self, app_token):
client = Spotify(app_token, max_limits_on=True)
s, = client.search('piano', ('track',), None, None, 1)
assert s.limit == 1
def client():
return Spotify('token')
def client():
return Spotify('token')
def test_token_is_given_token(self):
token = MagicMock()
client = Spotify(token)
assert token is client.token
def test_modify_default_sender_instance(self):
instance = MagicMock()
from tekore import sender, Spotify
sender.default_sender_instance = instance
s = Spotify()
self.assertIs(s.sender, instance)
def test_instance_has_precedence_over_type(self):
instance = MagicMock()
type_mock = MagicMock(return_value=MagicMock())
from tekore import sender, Spotify
sender.default_sender_type = type_mock
sender.default_sender_instance = instance
s = Spotify()
self.assertIs(s.sender, instance)
async def sp(self, mask, target, args):
"""
Show currently playing track via Spotify. Needs to be authed.
%%sp
"""
token = await self.get_spotify_token(mask.nick)
if not token:
return "Log in with spotify first via setspotifyuser"
spotify = tk.Spotify(token, asynchronous=True)
currently_playing = await spotify.playback_currently_playing()
if currently_playing is None or currently_playing.item is None:
return f"{mask.nick} is not playing anything at the moment."
playing_type = currently_playing.currently_playing_type
if playing_type == tk.model.CurrentlyPlayingType.track:
track = currently_playing.item
artists = ', '.join(artist.name for artist in track.artists)
album = track.album
response = f"{mask.nick} is playing {artists} - “{track.name}”"
if album.name != track.name:
response += f" (“{album.name}”)"
response += f" ({album.release_date[:4]})"
response += f" ({track.uri})"
return response
def connect(self):
if self.cred is None:
self.prep_cred()
if self.spotify is None:
if self.token is None:
self.load_token()
if self.token:
print("Init spotify support")
self.spotify = tk.Spotify(self.token)