From 19449da361d5cf33486b3f022bdcda3f3ee693b6 Mon Sep 17 00:00:00 2001 From: Michael Birtwell Date: Sat, 7 Jan 2017 14:56:13 +0000 Subject: [PATCH] Add unittest for state per authorize --- tests/test_oauth.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/test_oauth.py b/tests/test_oauth.py index 98f7548..d95ea8f 100644 --- a/tests/test_oauth.py +++ b/tests/test_oauth.py @@ -7,6 +7,7 @@ try: import unittest.mock as mock except ImportError: import mock +import six.moves.urllib.parse as urllibparse patch = mock.patch DEFAULT = mock.DEFAULT @@ -114,5 +115,37 @@ class OAuthCacheTest(unittest.TestCase): 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__': unittest.main()