mirror of
https://github.com/c0de-archive/spotipy.git
synced 2024-11-04 23:17:48 +00:00
Test Requests session functionality.
This commit is contained in:
parent
62ced74126
commit
004ef98a2c
@ -82,7 +82,7 @@ class Spotify(object):
|
||||
|
||||
r = self._session.request(method, url, headers=headers, **args)
|
||||
|
||||
if self.trace:
|
||||
if self.trace: # pragma: no cover
|
||||
print()
|
||||
print(method, r.url)
|
||||
if payload:
|
||||
@ -95,7 +95,7 @@ class Spotify(object):
|
||||
-1, u'%s:\n %s' % (r.url, r.json()['error']['message']))
|
||||
if len(r.text) > 0:
|
||||
results = r.json()
|
||||
if self.trace:
|
||||
if self.trace: # pragma: no cover
|
||||
print('RESP', results)
|
||||
print()
|
||||
return results
|
||||
|
@ -2,6 +2,7 @@
|
||||
import spotipy
|
||||
import unittest
|
||||
import pprint
|
||||
from spotipy.client import SpotifyException
|
||||
|
||||
|
||||
class TestSpotipy(unittest.TestCase):
|
||||
@ -114,6 +115,26 @@ class TestSpotipy(unittest.TestCase):
|
||||
except spotipy.SpotifyException:
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_unauthenticated_post_fails(self):
|
||||
with self.assertRaises(SpotifyException) as cm:
|
||||
self.spotify.user_playlist_create("spotify", "Best hits of the 90s")
|
||||
self.assertEqual(cm.exception.http_status, 401)
|
||||
|
||||
def test_custom_requests_session(self):
|
||||
from requests import Session
|
||||
sess = Session()
|
||||
sess.headers["user-agent"] = "spotipy-test"
|
||||
with_custom_session = spotipy.Spotify(requests_session=sess)
|
||||
self.assertTrue(with_custom_session.user(user="akx")["uri"] == "spotify:user:akx")
|
||||
|
||||
def test_force_no_requests_session(self):
|
||||
from requests import Session
|
||||
with_no_session = spotipy.Spotify(requests_session=False)
|
||||
self.assertFalse(isinstance(with_no_session._session, Session))
|
||||
self.assertTrue(with_no_session.user(user="akx")["uri"] == "spotify:user:akx")
|
||||
|
||||
|
||||
|
||||
'''
|
||||
Need tests for:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user