mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-05 07:27:47 +00:00
Cleaning up some tests
This commit is contained in:
parent
9d51880728
commit
4587a0771d
@ -11,7 +11,7 @@ import sys
|
|||||||
|
|
||||||
client_credentials_manager = SpotifyClientCredentials()
|
client_credentials_manager = SpotifyClientCredentials()
|
||||||
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
||||||
sp.trace=True
|
sp.trace=False
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
artist_name = ' '.join(sys.argv[1:])
|
artist_name = ' '.join(sys.argv[1:])
|
||||||
@ -21,12 +21,8 @@ if len(sys.argv) > 1:
|
|||||||
print(' ', i, t['name'])
|
print(' ', i, t['name'])
|
||||||
tids.append(t['uri'])
|
tids.append(t['uri'])
|
||||||
|
|
||||||
print(tids)
|
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
features = sp.audio_features(tids)
|
features = sp.audio_features(tids)
|
||||||
delta = time.time() - start
|
delta = time.time() - start
|
||||||
print ("features", features)
|
|
||||||
print(json.dumps(features, indent=4))
|
print(json.dumps(features, indent=4))
|
||||||
|
|
||||||
print ("features retrieved in %.2f seconds" % (delta,))
|
print ("features retrieved in %.2f seconds" % (delta,))
|
||||||
|
@ -21,6 +21,5 @@ if len(sys.argv) > 1:
|
|||||||
start = time.time()
|
start = time.time()
|
||||||
features = sp.audio_features(tids)
|
features = sp.audio_features(tids)
|
||||||
delta = time.time() - start
|
delta = time.time() - start
|
||||||
print ("features", features)
|
|
||||||
print(json.dumps(features, indent=4))
|
print(json.dumps(features, indent=4))
|
||||||
print ("features retrieved in %.2f seconds" % (delta,))
|
print ("features retrieved in %.2f seconds" % (delta,))
|
||||||
|
@ -97,6 +97,7 @@ class Spotify(object):
|
|||||||
|
|
||||||
if self.trace: # pragma: no cover
|
if self.trace: # pragma: no cover
|
||||||
print()
|
print()
|
||||||
|
print ('http status', r.status_code)
|
||||||
print(method, r.url)
|
print(method, r.url)
|
||||||
if payload:
|
if payload:
|
||||||
print("DATA", json.dumps(payload))
|
print("DATA", json.dumps(payload))
|
||||||
@ -547,6 +548,30 @@ class Spotify(object):
|
|||||||
tlist = [self._get_id('track', t) for t in tracks]
|
tlist = [self._get_id('track', t) for t in tracks]
|
||||||
return self._put('me/tracks/?ids=' + ','.join(tlist))
|
return self._put('me/tracks/?ids=' + ','.join(tlist))
|
||||||
|
|
||||||
|
def current_user_top_artists(self, limit=20, offset=0, time_range='6-months'):
|
||||||
|
''' Get the current user's top artists
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
- limit - the number of entities to return
|
||||||
|
- offset - the index of the first entity to return
|
||||||
|
- time_range - Over what time frame are the affinities computed.
|
||||||
|
Valid-values: all-time, 6-months, 14-days. Default: 6-months
|
||||||
|
'''
|
||||||
|
return self._get('me/toplists/artists', args={'time-range':time_range},
|
||||||
|
limit=limit,offset=offset)
|
||||||
|
|
||||||
|
def current_user_top_tracks(self, limit=20, offset=0, time_range='6-months'):
|
||||||
|
''' Get the current user's top tracks
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
- limit - the number of entities to return
|
||||||
|
- offset - the index of the first entity to return
|
||||||
|
- time_range - Over what time frame are the affinities computed.
|
||||||
|
Valid-values: all-time, 6-months, 14-days. Default: 6-months
|
||||||
|
'''
|
||||||
|
return self._get('me/toplists/tracks', args={'time-range':time_range},
|
||||||
|
limit=limit,offset=offset)
|
||||||
|
|
||||||
|
|
||||||
def featured_playlists(self, locale=None, country=None,
|
def featured_playlists(self, locale=None, country=None,
|
||||||
timestamp=None, limit=20, offset = 0):
|
timestamp=None, limit=20, offset = 0):
|
||||||
@ -636,8 +661,8 @@ class Spotify(object):
|
|||||||
results = self._get('audio-features?ids=' + ','.join(tlist))
|
results = self._get('audio-features?ids=' + ','.join(tlist))
|
||||||
# the response has changed, look for the new style first, and if
|
# the response has changed, look for the new style first, and if
|
||||||
# its not there, fallback on the old style
|
# its not there, fallback on the old style
|
||||||
if 'audio_attributes' in results:
|
if 'audio_features' in results:
|
||||||
return results['audio_attributes']
|
return results['audio_features']
|
||||||
else:
|
else:
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ from spotipy import util
|
|||||||
import unittest
|
import unittest
|
||||||
import pprint
|
import pprint
|
||||||
import sys
|
import sys
|
||||||
|
import simplejson as json
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Since these tests require authentication they are maintained
|
Since these tests require authentication they are maintained
|
||||||
@ -173,25 +174,6 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
self.assertTrue(playlist['tracks']['total'] == 3)
|
self.assertTrue(playlist['tracks']['total'] == 3)
|
||||||
self.assertTrue(len(playlist['tracks']['items']) == 3)
|
self.assertTrue(len(playlist['tracks']['items']) == 3)
|
||||||
|
|
||||||
def test_audio_features(self):
|
|
||||||
results = spotify.audio_features(self.four_tracks)
|
|
||||||
self.assertTrue(len(results) == len(self.four_tracks))
|
|
||||||
for attr in results:
|
|
||||||
assert('speechiness' in attr)
|
|
||||||
|
|
||||||
def test_audio_features_with_bad_track(self):
|
|
||||||
bad_tracks = ['spotify:track:bad']
|
|
||||||
input = self.four_tracks + bad_tracks
|
|
||||||
results = spotify.audio_features(input)
|
|
||||||
self.assertTrue(len(results) == len(input))
|
|
||||||
none_count = 0
|
|
||||||
for attr in results:
|
|
||||||
if attr == None:
|
|
||||||
none_count +=1
|
|
||||||
else:
|
|
||||||
assert('speechiness' in attr)
|
|
||||||
self.assertTrue(none_count == len(bad_tracks))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
username = sys.argv[1]
|
username = sys.argv[1]
|
||||||
|
@ -38,7 +38,6 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
def test_audio_features(self):
|
def test_audio_features(self):
|
||||||
print "test audio features"
|
|
||||||
results = spotify.audio_features(self.four_tracks)
|
results = spotify.audio_features(self.four_tracks)
|
||||||
self.assertTrue(len(results) == len(self.four_tracks))
|
self.assertTrue(len(results) == len(self.four_tracks))
|
||||||
for track in results:
|
for track in results:
|
||||||
@ -49,7 +48,6 @@ class AuthTestSpotipy(unittest.TestCase):
|
|||||||
bad_tracks = ['spotify:track:bad']
|
bad_tracks = ['spotify:track:bad']
|
||||||
input = bad_tracks + self.four_tracks + bad_tracks
|
input = bad_tracks + self.four_tracks + bad_tracks
|
||||||
results = spotify.audio_features(input)
|
results = spotify.audio_features(input)
|
||||||
print(json.dumps(results, indent=4))
|
|
||||||
self.assertTrue(len(results) == len(input))
|
self.assertTrue(len(results) == len(input))
|
||||||
for track in results[:-1]:
|
for track in results[:-1]:
|
||||||
assert('speechiness' in track)
|
assert('speechiness' in track)
|
||||||
|
Loading…
Reference in New Issue
Block a user