2014-04-05 13:12:01 +00:00
|
|
|
# -*- coding: latin-1 -*-
|
|
|
|
import spotipy
|
|
|
|
import unittest
|
2014-05-16 11:56:59 +00:00
|
|
|
import pprint
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestSpotipy(unittest.TestCase):
|
|
|
|
|
|
|
|
creep_urn = 'spotify:track:3HfB5hBU0dmBt8T0iCmH42'
|
|
|
|
creep_id = '3HfB5hBU0dmBt8T0iCmH42'
|
|
|
|
creep_url = 'http://open.spotify.com/track/3HfB5hBU0dmBt8T0iCmH42'
|
|
|
|
el_scorcho_urn = 'spotify:track:0Svkvt5I79wficMFgaqEQJ'
|
|
|
|
pinkerton_urn = 'spotify:album:04xe676vyiTeYNXw15o9jT'
|
|
|
|
weezer_urn = 'spotify:artist:3jOstUTkEu2JkjvRdBA5Gu'
|
|
|
|
pablo_honey_urn = 'spotify:album:6AZv3m27uyRxi8KyJSfUxL'
|
2014-04-05 18:52:57 +00:00
|
|
|
radiohead_urn = 'spotify:artist:4Z8W4fKeB5YxbusRsdQVPb'
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
bad_id = 'BAD_ID'
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.spotify = spotipy.Spotify()
|
|
|
|
|
|
|
|
def test_artist_urn(self):
|
|
|
|
artist = self.spotify.artist(self.radiohead_urn)
|
2014-04-05 18:52:57 +00:00
|
|
|
self.assertTrue(artist['name'] == u'Radiohead')
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
def test_artists(self):
|
|
|
|
results = self.spotify.artists([self.weezer_urn, self.radiohead_urn])
|
|
|
|
self.assertTrue('artists' in results)
|
|
|
|
self.assertTrue(len(results['artists']) == 2)
|
|
|
|
|
|
|
|
def test_album_urn(self):
|
|
|
|
album = self.spotify.album(self.pinkerton_urn)
|
2014-04-05 18:52:57 +00:00
|
|
|
self.assertTrue(album['name'] == u'Pinkerton')
|
2014-04-05 13:12:01 +00:00
|
|
|
|
2014-05-16 11:56:59 +00:00
|
|
|
def test_album_tracks(self):
|
|
|
|
results = self.spotify.album_tracks(self.pinkerton_urn)
|
|
|
|
self.assertTrue(len(results['items']) == 10)
|
|
|
|
|
2014-04-05 13:12:01 +00:00
|
|
|
def test_albums(self):
|
|
|
|
results = self.spotify.albums([self.pinkerton_urn, self.pablo_honey_urn])
|
|
|
|
self.assertTrue('albums' in results)
|
|
|
|
self.assertTrue(len(results['albums']) == 2)
|
|
|
|
|
|
|
|
def test_track_urn(self):
|
|
|
|
track = self.spotify.track(self.creep_urn)
|
2014-04-05 18:52:57 +00:00
|
|
|
self.assertTrue(track['name'] == u'Creep')
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
def test_track_id(self):
|
|
|
|
track = self.spotify.track(self.creep_id)
|
2014-04-05 18:52:57 +00:00
|
|
|
self.assertTrue(track['name'] == u'Creep')
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
def test_track_url(self):
|
|
|
|
track = self.spotify.track(self.creep_url)
|
2014-04-05 18:52:57 +00:00
|
|
|
self.assertTrue(track['name'] == u'Creep')
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
def test_tracks(self):
|
|
|
|
results = self.spotify.tracks([self.creep_url, self.el_scorcho_urn])
|
|
|
|
self.assertTrue('tracks' in results)
|
|
|
|
self.assertTrue(len(results['tracks']) == 2)
|
|
|
|
|
2014-05-16 11:56:59 +00:00
|
|
|
def test_artist_top_tracks(self):
|
|
|
|
results = self.spotify.artist_top_tracks(self.weezer_urn)
|
|
|
|
self.assertTrue('tracks' in results)
|
|
|
|
self.assertTrue(len(results['tracks']) == 10)
|
|
|
|
|
2014-08-20 18:04:29 +00:00
|
|
|
def test_artist_related_artists(self):
|
|
|
|
results = self.spotify.artist_related_artists(self.weezer_urn)
|
|
|
|
self.assertTrue('artists' in results)
|
|
|
|
self.assertTrue(len(results['artists']) == 20)
|
|
|
|
for artist in results['artists']:
|
|
|
|
if artist['name'] == 'Rivers Cuomo':
|
|
|
|
found = True
|
|
|
|
self.assertTrue(found)
|
|
|
|
|
2014-04-05 13:12:01 +00:00
|
|
|
def test_artist_search(self):
|
|
|
|
results = self.spotify.search(q='weezer', type='artist')
|
|
|
|
self.assertTrue('artists' in results)
|
2014-05-16 18:02:33 +00:00
|
|
|
self.assertTrue(len(results['artists']['items']) > 0)
|
|
|
|
self.assertTrue(results['artists']['items'][0]['name'] == 'Weezer')
|
2014-04-05 13:12:01 +00:00
|
|
|
|
2014-04-07 17:10:25 +00:00
|
|
|
def test_artist_albums(self):
|
|
|
|
results = self.spotify.artist_albums(self.weezer_urn)
|
2014-05-16 11:56:59 +00:00
|
|
|
self.assertTrue('items' in results)
|
|
|
|
self.assertTrue(len(results['items']) > 0)
|
|
|
|
|
|
|
|
found = False
|
|
|
|
for album in results['items']:
|
|
|
|
if album['name'] == 'Hurley':
|
|
|
|
found = True
|
|
|
|
|
|
|
|
self.assertTrue(found)
|
2014-04-07 17:10:25 +00:00
|
|
|
|
2014-04-05 13:12:01 +00:00
|
|
|
def test_album_search(self):
|
|
|
|
results = self.spotify.search(q='weezer pinkerton', type='album')
|
|
|
|
self.assertTrue('albums' in results)
|
2014-05-16 18:02:33 +00:00
|
|
|
self.assertTrue(len(results['albums']['items']) > 0)
|
2014-06-19 18:41:52 +00:00
|
|
|
self.assertTrue(results['albums']['items'][0]['name'].find('Pinkerton') >= 0)
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
def test_track_search(self):
|
|
|
|
results = self.spotify.search(q='el scorcho weezer', type='track')
|
|
|
|
self.assertTrue('tracks' in results)
|
2014-05-16 18:02:33 +00:00
|
|
|
self.assertTrue(len(results['tracks']['items']) > 0)
|
|
|
|
self.assertTrue(results['tracks']['items'][0]['name'] == 'El Scorcho')
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
def test_user(self):
|
2014-08-20 18:04:29 +00:00
|
|
|
user = self.spotify.user(user='plamere')
|
2014-05-16 11:56:59 +00:00
|
|
|
self.assertTrue(user['uri'] == 'spotify:user:plamere')
|
2014-04-05 13:12:01 +00:00
|
|
|
|
|
|
|
def test_track_bad_id(self):
|
|
|
|
try:
|
|
|
|
track = self.spotify.track(self.bad_id)
|
|
|
|
self.assertTrue(False)
|
|
|
|
except spotipy.SpotifyException:
|
|
|
|
self.assertTrue(True)
|
2014-04-05 18:52:57 +00:00
|
|
|
|
2014-08-20 18:04:29 +00:00
|
|
|
'''
|
|
|
|
Need tests for:
|
|
|
|
|
|
|
|
- next
|
|
|
|
- previous
|
|
|
|
- artist_related_artists
|
|
|
|
- user_playlists
|
|
|
|
- user_playlist
|
|
|
|
- user_playlist_create
|
|
|
|
- user_playlist_add_tracks
|
|
|
|
- user_playlist_replace_tracks
|
|
|
|
- user_playlist_remove_all_occurrences_of_tracks
|
|
|
|
- user_playlist_remove_specific_occurrences_of_tracks
|
|
|
|
- me
|
|
|
|
- current_user
|
|
|
|
- current_user_saved_tracks_delete
|
|
|
|
- current_user_saved_tracks_add
|
|
|
|
'''
|
|
|
|
|
2014-04-05 13:12:01 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|