Cleaning up some tests

This commit is contained in:
Paul Lamere 2016-02-20 08:54:11 -05:00
parent 9d51880728
commit 4587a0771d
5 changed files with 29 additions and 29 deletions

View File

@ -11,7 +11,7 @@ import sys
client_credentials_manager = SpotifyClientCredentials()
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
sp.trace=True
sp.trace=False
if len(sys.argv) > 1:
artist_name = ' '.join(sys.argv[1:])
@ -21,12 +21,8 @@ if len(sys.argv) > 1:
print(' ', i, t['name'])
tids.append(t['uri'])
print(tids)
start = time.time()
features = sp.audio_features(tids)
delta = time.time() - start
print ("features", features)
print(json.dumps(features, indent=4))
print ("features retrieved in %.2f seconds" % (delta,))

View File

@ -21,6 +21,5 @@ if len(sys.argv) > 1:
start = time.time()
features = sp.audio_features(tids)
delta = time.time() - start
print ("features", features)
print(json.dumps(features, indent=4))
print ("features retrieved in %.2f seconds" % (delta,))

View File

@ -97,6 +97,7 @@ class Spotify(object):
if self.trace: # pragma: no cover
print()
print ('http status', r.status_code)
print(method, r.url)
if payload:
print("DATA", json.dumps(payload))
@ -547,6 +548,30 @@ class Spotify(object):
tlist = [self._get_id('track', t) for t in tracks]
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,
timestamp=None, limit=20, offset = 0):
@ -636,8 +661,8 @@ class Spotify(object):
results = self._get('audio-features?ids=' + ','.join(tlist))
# the response has changed, look for the new style first, and if
# its not there, fallback on the old style
if 'audio_attributes' in results:
return results['audio_attributes']
if 'audio_features' in results:
return results['audio_features']
else:
return results

View File

@ -5,6 +5,7 @@ from spotipy import util
import unittest
import pprint
import sys
import simplejson as json
'''
Since these tests require authentication they are maintained
@ -173,25 +174,6 @@ class AuthTestSpotipy(unittest.TestCase):
self.assertTrue(playlist['tracks']['total'] == 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 len(sys.argv) > 1:
username = sys.argv[1]

View File

@ -38,7 +38,6 @@ class AuthTestSpotipy(unittest.TestCase):
def test_audio_features(self):
print "test audio features"
results = spotify.audio_features(self.four_tracks)
self.assertTrue(len(results) == len(self.four_tracks))
for track in results:
@ -49,7 +48,6 @@ class AuthTestSpotipy(unittest.TestCase):
bad_tracks = ['spotify:track:bad']
input = bad_tracks + self.four_tracks + bad_tracks
results = spotify.audio_features(input)
print(json.dumps(results, indent=4))
self.assertTrue(len(results) == len(input))
for track in results[:-1]:
assert('speechiness' in track)