From d18892a99e0efebf195d40d9067df64e0d929eac Mon Sep 17 00:00:00 2001 From: Paul Lamere Date: Sat, 31 Dec 2016 09:52:03 -0500 Subject: [PATCH] Added timeout test --- examples/test_request_timeout.py | 14 ++++++++++++++ tests/tests.py | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 examples/test_request_timeout.py diff --git a/examples/test_request_timeout.py b/examples/test_request_timeout.py new file mode 100644 index 0000000..167e4f1 --- /dev/null +++ b/examples/test_request_timeout.py @@ -0,0 +1,14 @@ +# shows artist info for a URN or URL + +import spotipy +import sys +import pprint + +if len(sys.argv) > 1: + search_str = sys.argv[1] +else: + search_str = 'Radiohead' + +sp = spotipy.Spotify(requests_timeout=.1) +result = sp.search(search_str) +pprint.pprint(result) diff --git a/tests/tests.py b/tests/tests.py index 8f57e24..7fc8c39 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -2,6 +2,7 @@ import spotipy import unittest import pprint +import requests from spotipy.client import SpotifyException @@ -105,6 +106,15 @@ class TestSpotipy(unittest.TestCase): self.assertTrue(found) + def test_search_timeout(self): + sp = spotipy.Spotify(requests_timeout=.1) + try: + results = sp.search(q='my*', type='track') + self.assertTrue(False, 'unexpected search timeout') + except requests.ReadTimeout: + self.assertTrue(True, 'expected search timeout') + + def test_album_search(self): results = self.spotify.search(q='weezer pinkerton', type='album') self.assertTrue('albums' in results)