diff options
Diffstat (limited to 'tests/test_pandora/test_client.py')
-rw-r--r-- | tests/test_pandora/test_client.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py index ce91e21..8d93e4c 100644 --- a/tests/test_pandora/test_client.py +++ b/tests/test_pandora/test_client.py | |||
@@ -1,6 +1,7 @@ | |||
1 | from unittest import TestCase | 1 | from unittest import TestCase |
2 | 2 | ||
3 | from pandora import errors | 3 | from pandora import errors |
4 | from pandora.models.pandora import AdItem | ||
4 | from pandora.client import APIClient, BaseAPIClient | 5 | from pandora.client import APIClient, BaseAPIClient |
5 | from pandora.py2compat import Mock, call, patch | 6 | from pandora.py2compat import Mock, call, patch |
6 | from tests.test_pandora.test_models import TestAdItem | 7 | from tests.test_pandora.test_models import TestAdItem |
@@ -63,6 +64,20 @@ class TestCallingAPIClient(TestCase): | |||
63 | client._authenticate.assert_called_with() | 64 | client._authenticate.assert_called_with() |
64 | transport.assert_has_calls([call("method"), call("method")]) | 65 | transport.assert_has_calls([call("method"), call("method")]) |
65 | 66 | ||
67 | def test_playlist_fetches_ads(self): | ||
68 | fake_playlist = { "items": [ | ||
69 | { "songName": "test" }, | ||
70 | { "adToken": "foo" }, | ||
71 | { "songName": "test" }, | ||
72 | ]} | ||
73 | with patch.object( | ||
74 | APIClient, '__call__', return_value=fake_playlist) as mock: | ||
75 | client = APIClient(Mock(), None, None, None, None) | ||
76 | client._authenticate = Mock() | ||
77 | |||
78 | items = client.get_playlist('token_mock') | ||
79 | self.assertIsInstance(items[1], AdItem) | ||
80 | |||
66 | def test_ad_support_enabled_parameters(self): | 81 | def test_ad_support_enabled_parameters(self): |
67 | with patch.object(APIClient, '__call__') as playlist_mock: | 82 | with patch.object(APIClient, '__call__') as playlist_mock: |
68 | transport = Mock(side_effect=[errors.InvalidAuthToken(), None]) | 83 | transport = Mock(side_effect=[errors.InvalidAuthToken(), None]) |
@@ -127,3 +142,47 @@ class TestGettingAds(TestCase): | |||
127 | 142 | ||
128 | self.assertRaises( | 143 | self.assertRaises( |
129 | errors.ParameterMissing, client.get_ad_item, '', 'token_mock') | 144 | errors.ParameterMissing, client.get_ad_item, '', 'token_mock') |
145 | |||
146 | |||
147 | class TestCreatingStation(TestCase): | ||
148 | |||
149 | def test_using_search_token(self): | ||
150 | client = APIClient(Mock(), None, None, None, None) | ||
151 | client.create_station(search_token="foo") | ||
152 | client.transport.assert_called_with( | ||
153 | "station.createStation", musicToken="foo") | ||
154 | |||
155 | def test_using_artist_token(self): | ||
156 | client = APIClient(Mock(), None, None, None, None) | ||
157 | client.create_station(artist_token="foo") | ||
158 | client.transport.assert_called_with( | ||
159 | "station.createStation", trackToken="foo", musicType="artist") | ||
160 | |||
161 | def test_using_track_token(self): | ||
162 | client = APIClient(Mock(), None, None, None, None) | ||
163 | client.create_station(track_token="foo") | ||
164 | client.transport.assert_called_with( | ||
165 | "station.createStation", trackToken="foo", musicType="song") | ||
166 | |||
167 | def test_with_no_token(self): | ||
168 | with self.assertRaises(KeyError): | ||
169 | client = APIClient(Mock(), None, None, None, None) | ||
170 | client.create_station() | ||
171 | |||
172 | |||
173 | class TestCreatingGenreStation(TestCase): | ||
174 | |||
175 | def test_has_initial_checksum(self): | ||
176 | fake_data = { | ||
177 | "categories": [ | ||
178 | { "categoryName": "foo", "stations": [] }, | ||
179 | ], | ||
180 | |||
181 | # Not actually part of the genre station response but is needed to | ||
182 | # fake out the mock for get_genre_stations_checksum | ||
183 | "checksum": "foo" | ||
184 | } | ||
185 | with patch.object(APIClient, '__call__', return_value=fake_data): | ||
186 | client = APIClient(Mock(), None, None, None, None) | ||
187 | station = client.get_genre_stations() | ||
188 | self.assertEqual(station.checksum, "foo") | ||