mirror of
https://github.com/c0de-archive/spotipy.git
synced 2025-01-06 14:52:50 +00:00
Merge pull request #150 from mbirtwell/state_per_authorize_tests
Add unittest for state per authorize
This commit is contained in:
commit
d2f047514d
@ -7,6 +7,7 @@ try:
|
|||||||
import unittest.mock as mock
|
import unittest.mock as mock
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import mock
|
import mock
|
||||||
|
import six.moves.urllib.parse as urllibparse
|
||||||
|
|
||||||
patch = mock.patch
|
patch = mock.patch
|
||||||
DEFAULT = mock.DEFAULT
|
DEFAULT = mock.DEFAULT
|
||||||
@ -114,5 +115,37 @@ class OAuthCacheTest(unittest.TestCase):
|
|||||||
self.assertTrue(fi.write.called)
|
self.assertTrue(fi.write.called)
|
||||||
|
|
||||||
|
|
||||||
|
class TestSpotifyOAuth(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_get_authorize_url_doesnt_pass_state_by_default(self):
|
||||||
|
oauth = SpotifyOAuth("CLID", "CLISEC", "REDIR")
|
||||||
|
|
||||||
|
url = oauth.get_authorize_url()
|
||||||
|
|
||||||
|
parsed_url = urllibparse.urlparse(url)
|
||||||
|
parsed_qs = urllibparse.parse_qs(parsed_url.query)
|
||||||
|
self.assertNotIn('state', parsed_qs)
|
||||||
|
|
||||||
|
def test_get_authorize_url_passes_state_from_constructor(self):
|
||||||
|
state = "STATE"
|
||||||
|
oauth = SpotifyOAuth("CLID", "CLISEC", "REDIR", state)
|
||||||
|
|
||||||
|
url = oauth.get_authorize_url()
|
||||||
|
|
||||||
|
parsed_url = urllibparse.urlparse(url)
|
||||||
|
parsed_qs = urllibparse.parse_qs(parsed_url.query)
|
||||||
|
self.assertEqual(parsed_qs['state'][0], state)
|
||||||
|
|
||||||
|
def test_get_authorize_url_passes_state_from_func_call(self):
|
||||||
|
state = "STATE"
|
||||||
|
oauth = SpotifyOAuth("CLID", "CLISEC", "REDIR", "NOT STATE")
|
||||||
|
|
||||||
|
url = oauth.get_authorize_url(state=state)
|
||||||
|
|
||||||
|
parsed_url = urllibparse.urlparse(url)
|
||||||
|
parsed_qs = urllibparse.parse_qs(parsed_url.query)
|
||||||
|
self.assertEqual(parsed_qs['state'][0], state)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user