From 9d518807285045f72997c3d43093d9f8fbe47b45 Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Sat, 20 Feb 2016 08:33:31 -0500 Subject: [PATCH] Added some audio feature tests --- tests/authtests2.py | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/authtests2.py diff --git a/tests/authtests2.py b/tests/authtests2.py new file mode 100644 index 0000000..0b2ba07 --- /dev/null +++ b/tests/authtests2.py @@ -0,0 +1,63 @@ +# -*- coding: latin-1 -*- + +import spotipy +from spotipy import util +import unittest +import pprint +import sys +import simplejson as json +from spotipy.oauth2 import SpotifyClientCredentials + +''' + Since these tests require authentication they are maintained + separately from the other tests. + + These tests try to be benign and leave your collection and + playlists in a relatively stable state. +''' + +class AuthTestSpotipy(unittest.TestCase): + ''' + These tests require user authentication + ''' + + playlist = "spotify:user:plamere:playlist:2oCEWyyAPbZp9xhVSxZavx" + four_tracks = ["spotify:track:6RtPijgfPKROxEzTHNRiDp", + "spotify:track:7IHOIqZUUInxjVkko181PB", + "4VrWlk8IQxevMvERoX08iC", + "http://open.spotify.com/track/3cySlItpiPiIAzU3NyHCJf"] + + two_tracks = ["spotify:track:6RtPijgfPKROxEzTHNRiDp", + "spotify:track:7IHOIqZUUInxjVkko181PB"] + + other_tracks=["spotify:track:2wySlB6vMzCbQrRnNGOYKa", + "spotify:track:29xKs5BAHlmlX1u4gzQAbJ", + "spotify:track:1PB7gRWcvefzu7t3LJLUlf"] + + bad_id = 'BAD_ID' + + + 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: + assert('speechiness' in track) + + def test_audio_features_with_bad_track(self): + bad_tracks = [] + 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) + self.assertTrue(results[-1] == None) + + +if __name__ == '__main__': + client_credentials_manager = SpotifyClientCredentials() + spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager) + spotify.trace = False + unittest.main()