mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-07 23:22:49 +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)
|
r = self._session.request(method, url, headers=headers, **args)
|
||||||
|
|
||||||
if self.trace:
|
if self.trace: # pragma: no cover
|
||||||
print()
|
print()
|
||||||
print(method, r.url)
|
print(method, r.url)
|
||||||
if payload:
|
if payload:
|
||||||
@ -95,7 +95,7 @@ class Spotify(object):
|
|||||||
-1, u'%s:\n %s' % (r.url, r.json()['error']['message']))
|
-1, u'%s:\n %s' % (r.url, r.json()['error']['message']))
|
||||||
if len(r.text) > 0:
|
if len(r.text) > 0:
|
||||||
results = r.json()
|
results = r.json()
|
||||||
if self.trace:
|
if self.trace: # pragma: no cover
|
||||||
print('RESP', results)
|
print('RESP', results)
|
||||||
print()
|
print()
|
||||||
return results
|
return results
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
import spotipy
|
import spotipy
|
||||||
import unittest
|
import unittest
|
||||||
import pprint
|
import pprint
|
||||||
|
from spotipy.client import SpotifyException
|
||||||
|
|
||||||
|
|
||||||
class TestSpotipy(unittest.TestCase):
|
class TestSpotipy(unittest.TestCase):
|
||||||
@ -114,6 +115,26 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
except spotipy.SpotifyException:
|
except spotipy.SpotifyException:
|
||||||
self.assertTrue(True)
|
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:
|
Need tests for:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user