aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSkybound1 <mgupta94@hotmail.co.uk>2018-12-10 19:10:49 +0100
committerMike Crute <crutem@amazon.com>2018-12-10 10:10:49 -0800
commit9e49c086a86deff4ae85d802e9d57278f1ac4636 (patch)
tree1b68ce4c19b7dcd6281118acd702b920bc59417d /tests
parentd74a05605401926b6b6fc694753c7de19f67c419 (diff)
downloadpydora-9e49c086a86deff4ae85d802e9d57278f1ac4636.tar.bz2
pydora-9e49c086a86deff4ae85d802e9d57278f1ac4636.tar.xz
pydora-9e49c086a86deff4ae85d802e9d57278f1ac4636.zip
Enhancement: Adds additional audio urls (#58)
* Adds support for additionalAudioUrl for station.getPlaylist * Fixes broken tests * Reworks use of iterables for additional audio urls and adds associated tests * Moves parsing additional url response into a syntethic field * Adds tests for additional urls field
Diffstat (limited to 'tests')
-rw-r--r--tests/test_pandora/test_client.py68
-rw-r--r--tests/test_pandora/test_models.py33
2 files changed, 100 insertions, 1 deletions
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py
index 6c61355..d24ea28 100644
--- a/tests/test_pandora/test_client.py
+++ b/tests/test_pandora/test_client.py
@@ -1,7 +1,7 @@
1from unittest import TestCase 1from unittest import TestCase
2 2
3from pandora import errors 3from pandora import errors
4from pandora.models.pandora import AdItem 4from pandora.models.pandora import AdItem, AdditionalAudioUrl
5from pandora.client import APIClient, BaseAPIClient 5from pandora.client import APIClient, BaseAPIClient
6from pandora.py2compat import Mock, call, patch 6from pandora.py2compat import Mock, call, patch
7from tests.test_pandora.test_models import TestAdItem 7from tests.test_pandora.test_models import TestAdItem
@@ -87,6 +87,7 @@ class TestCallingAPIClient(TestCase):
87 client.get_playlist('token_mock') 87 client.get_playlist('token_mock')
88 88
89 playlist_mock.assert_has_calls([call("station.getPlaylist", 89 playlist_mock.assert_has_calls([call("station.getPlaylist",
90 additionalAudioUrl='',
90 audioAdPodCapable=True, 91 audioAdPodCapable=True,
91 includeTrackLength=True, 92 includeTrackLength=True,
92 stationToken='token_mock', 93 stationToken='token_mock',
@@ -186,3 +187,68 @@ class TestCreatingGenreStation(TestCase):
186 client = APIClient(Mock(), None, None, None, None) 187 client = APIClient(Mock(), None, None, None, None)
187 station = client.get_genre_stations() 188 station = client.get_genre_stations()
188 self.assertEqual(station.checksum, "foo") 189 self.assertEqual(station.checksum, "foo")
190
191
192class TestAdditionalUrls(TestCase):
193
194 def test_non_iterable_string(self):
195 with self.assertRaises(TypeError):
196 transport = Mock(side_effect=[errors.InvalidAuthToken(), None])
197
198 client = APIClient(transport, None, None, None, None)
199 client._authenticate = Mock()
200
201 client.get_playlist('token_mock', additional_urls='')
202
203 def test_non_iterable_other(self):
204 with self.assertRaises(TypeError):
205 transport = Mock(side_effect=[errors.InvalidAuthToken(), None])
206
207 client = APIClient(transport, None, None, None, None)
208 client._authenticate = Mock()
209
210 client.get_playlist('token_mock',
211 additional_urls=AdditionalAudioUrl.HTTP_32_WMA)
212
213 def test_without_enum(self):
214 with patch.object(APIClient, '__call__') as playlist_mock:
215 transport = Mock(side_effect=[errors.InvalidAuthToken(), None])
216
217 client = APIClient(transport, None, None, None, None)
218 client._authenticate = Mock()
219
220 urls = ['HTTP_128_MP3',
221 'HTTP_24_AACPLUS_ADTS']
222
223 desired = 'HTTP_128_MP3,HTTP_24_AACPLUS_ADTS'
224
225 client.get_playlist('token_mock', additional_urls=urls)
226
227 playlist_mock.assert_has_calls([call("station.getPlaylist",
228 additionalAudioUrl=desired,
229 audioAdPodCapable=True,
230 includeTrackLength=True,
231 stationToken='token_mock',
232 xplatformAdCapable=True)])
233
234
235 def test_with_enum(self):
236 with patch.object(APIClient, '__call__') as playlist_mock:
237 transport = Mock(side_effect=[errors.InvalidAuthToken(), None])
238
239 client = APIClient(transport, None, None, None, None)
240 client._authenticate = Mock()
241
242 urls = [AdditionalAudioUrl.HTTP_128_MP3,
243 AdditionalAudioUrl.HTTP_24_AACPLUS_ADTS]
244
245 desired = 'HTTP_128_MP3,HTTP_24_AACPLUS_ADTS'
246
247 client.get_playlist('token_mock', additional_urls=urls)
248
249 playlist_mock.assert_has_calls([call("station.getPlaylist",
250 additionalAudioUrl=desired,
251 audioAdPodCapable=True,
252 includeTrackLength=True,
253 stationToken='token_mock',
254 xplatformAdCapable=True)])
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py
index ce71ef8..410b0de 100644
--- a/tests/test_pandora/test_models.py
+++ b/tests/test_pandora/test_models.py
@@ -52,6 +52,39 @@ class TestDateField(TestCase):
52 self.assertEqual(expected, model.date_field.replace(microsecond=0)) 52 self.assertEqual(expected, model.date_field.replace(microsecond=0))
53 53
54 54
55class TestAdditionalUrlField(TestCase):
56
57 def test_single_url(self):
58 dummy_data = {
59 '_paramAdditionalUrls': ['foo']
60 }
61
62 field = pm.AdditionalUrlField("additionalAudioUrl")
63
64 ret = field.formatter(None, dummy_data, 'test')
65
66 self.assertEqual(ret, {'foo': 'test'})
67
68 def test_multiple_urls(self):
69 dummy_data = {
70 '_paramAdditionalUrls': [
71 'abc',
72 'def',
73 ]
74 }
75
76 field = pm.AdditionalUrlField("additionalAudioUrl")
77
78 ret = field.formatter(None, dummy_data, ['foo', 'bar'])
79
80 expected = {
81 'abc': 'foo',
82 'def': 'bar',
83 }
84
85 self.assertEqual(ret, expected)
86
87
55class TestPandoraModel(TestCase): 88class TestPandoraModel(TestCase):
56 89
57 JSON_DATA = { 90 JSON_DATA = {