mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-06-19 01:03:53 +00:00
Miscellaneous fixes - clean up tests
This commit is contained in:
parent
502a56f987
commit
e9edf2a255
1
.gitignore
vendored
1
.gitignore
vendored
@ -55,3 +55,4 @@ docs/_build/
|
|||||||
|
|
||||||
.*
|
.*
|
||||||
archive
|
archive
|
||||||
|
*.sh
|
||||||
|
|||||||
@ -1,2 +1,3 @@
|
|||||||
|
mock==2.0.0
|
||||||
requests==2.3.0
|
requests==2.3.0
|
||||||
six==1.10.0
|
six==1.10.0
|
||||||
1
setup.py
1
setup.py
@ -9,6 +9,7 @@ setup(
|
|||||||
author_email="paul@echonest.com",
|
author_email="paul@echonest.com",
|
||||||
url='http://spotipy.readthedocs.org/',
|
url='http://spotipy.readthedocs.org/',
|
||||||
install_requires=[
|
install_requires=[
|
||||||
|
'mock>=2.0.0',
|
||||||
'requests>=2.3.0',
|
'requests>=2.3.0',
|
||||||
'six>=1.10.0',
|
'six>=1.10.0',
|
||||||
],
|
],
|
||||||
|
|||||||
@ -60,7 +60,7 @@ class Spotify(object):
|
|||||||
def __init__(self, auth=None, requests_session=True,
|
def __init__(self, auth=None, requests_session=True,
|
||||||
client_credentials_manager=None, proxies=None, requests_timeout=None):
|
client_credentials_manager=None, proxies=None, requests_timeout=None):
|
||||||
"""
|
"""
|
||||||
Create a Spotify API object.
|
Creates a Spotify API client.
|
||||||
|
|
||||||
:param auth: An authorization token (optional)
|
:param auth: An authorization token (optional)
|
||||||
:param requests_session:
|
:param requests_session:
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'prompt_for_user_token9'
|
'prompt_for_user_token'
|
||||||
]
|
]
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|||||||
@ -1,27 +1,36 @@
|
|||||||
# -*- coding: latin-1 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
import spotipy
|
""" Client Credentials Requests Tests """
|
||||||
from spotipy.oauth2 import SpotifyClientCredentials
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
'''
|
sys.path.insert(0, os.path.abspath(os.pardir))
|
||||||
Client Credentials Requests Tests
|
|
||||||
'''
|
from spotipy import (
|
||||||
|
Spotify,
|
||||||
|
SpotifyClientCredentials,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ClientCredentialsTestSpotipy(unittest.TestCase):
|
class ClientCredentialsTestSpotipy(unittest.TestCase):
|
||||||
'''
|
'''
|
||||||
These tests require user authentication
|
These tests require user authentication
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(self):
|
||||||
|
self.spotify = Spotify(client_credentials_manager=SpotifyClientCredentials())
|
||||||
|
self.spotify.trace = False
|
||||||
|
|
||||||
muse_urn = 'spotify:artist:12Chz98pHFMPJEknJQMWvI'
|
muse_urn = 'spotify:artist:12Chz98pHFMPJEknJQMWvI'
|
||||||
|
|
||||||
def test_request_with_token(self):
|
def test_request_with_token(self):
|
||||||
artist = spotify.artist(self.muse_urn)
|
artist = self.spotify.artist(self.muse_urn)
|
||||||
self.assertTrue(artist['name'] == 'Muse')
|
self.assertTrue(artist['name'] == 'Muse')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
spotify_cc = SpotifyClientCredentials()
|
|
||||||
spotify = spotipy.Spotify(client_credentials_manager=spotify_cc)
|
|
||||||
spotify.trace = False
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@ -1,8 +1,15 @@
|
|||||||
from spotipy.oauth2 import SpotifyOAuth
|
# -*- coding: utf-8 -*-
|
||||||
import json
|
|
||||||
import io
|
import io
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.abspath(os.pardir))
|
||||||
|
|
||||||
|
from spotipy import SpotifyOAuth
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import unittest.mock as mock
|
import unittest.mock as mock
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -166,4 +173,5 @@ class TestSpotifyOAuth(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
@ -1,9 +1,19 @@
|
|||||||
# -*- coding: latin-1 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import spotipy
|
|
||||||
import unittest
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from spotipy.client import SpotifyException
|
|
||||||
|
sys.path.insert(0, os.path.abspath(os.pardir))
|
||||||
|
|
||||||
|
from spotipy import (
|
||||||
|
prompt_for_user_token,
|
||||||
|
Spotify,
|
||||||
|
SpotifyException,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestSpotipy(unittest.TestCase):
|
class TestSpotipy(unittest.TestCase):
|
||||||
@ -22,8 +32,14 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
|
|
||||||
bad_id = 'BAD_ID'
|
bad_id = 'BAD_ID'
|
||||||
|
|
||||||
def setUp(self):
|
@classmethod
|
||||||
self.spotify = spotipy.Spotify()
|
def setUpClass(self):
|
||||||
|
self.token = os.getenv('SPOTIPY_CLIENT_TOKEN')
|
||||||
|
if not self.token:
|
||||||
|
raise Exception('Set your Spotify client app token via the environment variable `SPOTIPY_CLIENT_TOKEN`')
|
||||||
|
|
||||||
|
self.spotify = Spotify(auth=self.token)
|
||||||
|
|
||||||
|
|
||||||
def test_artist_urn(self):
|
def test_artist_urn(self):
|
||||||
artist = self.spotify.artist(self.radiohead_urn)
|
artist = self.spotify.artist(self.radiohead_urn)
|
||||||
@ -74,7 +90,7 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
try:
|
try:
|
||||||
track = self.spotify.track(self.el_scorcho_bad_urn)
|
track = self.spotify.track(self.el_scorcho_bad_urn)
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
except spotipy.SpotifyException:
|
except SpotifyException:
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
|
|
||||||
def test_tracks(self):
|
def test_tracks(self):
|
||||||
@ -121,11 +137,11 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
self.assertTrue(found)
|
self.assertTrue(found)
|
||||||
|
|
||||||
def test_search_timeout(self):
|
def test_search_timeout(self):
|
||||||
sp = spotipy.Spotify(requests_timeout=.1)
|
sp = Spotify(auth=self.token, requests_timeout=.1)
|
||||||
try:
|
try:
|
||||||
results = sp.search(q='my*', type='track')
|
results = sp.search(q='my*', type='track')
|
||||||
self.assertTrue(False, 'unexpected search timeout')
|
self.assertTrue(False, 'unexpected search timeout')
|
||||||
except requests.ReadTimeout:
|
except requests.Timeout:
|
||||||
self.assertTrue(True, 'expected search timeout')
|
self.assertTrue(True, 'expected search timeout')
|
||||||
|
|
||||||
|
|
||||||
@ -149,14 +165,14 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
try:
|
try:
|
||||||
track = self.spotify.track(self.bad_id)
|
track = self.spotify.track(self.bad_id)
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
except spotipy.SpotifyException:
|
except SpotifyException:
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
|
|
||||||
def test_track_bad_id(self):
|
def test_track_bad_id(self):
|
||||||
try:
|
try:
|
||||||
track = self.spotify.track(self.bad_id)
|
track = self.spotify.track(self.bad_id)
|
||||||
self.assertTrue(False)
|
self.assertTrue(False)
|
||||||
except spotipy.SpotifyException:
|
except SpotifyException:
|
||||||
self.assertTrue(True)
|
self.assertTrue(True)
|
||||||
|
|
||||||
def test_unauthenticated_post_fails(self):
|
def test_unauthenticated_post_fails(self):
|
||||||
@ -166,20 +182,17 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
cm.exception.http_status == 403)
|
cm.exception.http_status == 403)
|
||||||
|
|
||||||
def test_custom_requests_session(self):
|
def test_custom_requests_session(self):
|
||||||
from requests import Session
|
sess = requests.Session()
|
||||||
sess = Session()
|
|
||||||
sess.headers["user-agent"] = "spotipy-test"
|
sess.headers["user-agent"] = "spotipy-test"
|
||||||
with_custom_session = spotipy.Spotify(requests_session=sess)
|
with_custom_session = Spotify(auth=self.token, requests_session=sess)
|
||||||
self.assertTrue(with_custom_session.user(user="akx")["uri"] == "spotify:user:akx")
|
self.assertTrue(with_custom_session.user(user="akx")["uri"] == "spotify:user:akx")
|
||||||
|
|
||||||
def test_force_no_requests_session(self):
|
def test_force_no_requests_session(self):
|
||||||
from requests import Session
|
with_no_session = Spotify(auth=self.token, requests_session=False)
|
||||||
with_no_session = spotipy.Spotify(requests_session=False)
|
self.assertFalse(isinstance(with_no_session._session, requests.Session))
|
||||||
self.assertFalse(isinstance(with_no_session._session, Session))
|
|
||||||
self.assertTrue(with_no_session.user(user="akx")["uri"] == "spotify:user:akx")
|
self.assertTrue(with_no_session.user(user="akx")["uri"] == "spotify:user:akx")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Need tests for:
|
Need tests for:
|
||||||
|
|
||||||
@ -188,4 +201,5 @@ class TestSpotipy(unittest.TestCase):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user