diff options
author | Mike Crute <mike@crute.us> | 2020-06-08 18:20:57 +0000 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2020-06-08 18:20:57 +0000 |
commit | 3681a9b616212656462efa0a9c78722f90cca442 (patch) | |
tree | 0199712af2f8abc5635d57d7e18ec63fe6d8b58e /tests/test_pandora/test_models.py | |
parent | 13b779eafd66a37ad5c50fa9be2bbc7962a73fce (diff) | |
download | pydora-3681a9b616212656462efa0a9c78722f90cca442.tar.bz2 pydora-3681a9b616212656462efa0a9c78722f90cca442.tar.xz pydora-3681a9b616212656462efa0a9c78722f90cca442.zip |
Use black for formatting
I don't particularly like the black formatter (does anybody, really?)
but it's guaranteed to be consistent so it should prevent nitpicking
style.
Diffstat (limited to 'tests/test_pandora/test_models.py')
-rw-r--r-- | tests/test_pandora/test_models.py | 303 |
1 files changed, 162 insertions, 141 deletions
diff --git a/tests/test_pandora/test_models.py b/tests/test_pandora/test_models.py index cb650df..16307b4 100644 --- a/tests/test_pandora/test_models.py +++ b/tests/test_pandora/test_models.py | |||
@@ -14,7 +14,6 @@ import pandora.models.playlist as plm | |||
14 | 14 | ||
15 | 15 | ||
16 | class TestField(TestCase): | 16 | class TestField(TestCase): |
17 | |||
18 | def test_defaults(self): | 17 | def test_defaults(self): |
19 | field = m.Field("name") | 18 | field = m.Field("name") |
20 | 19 | ||
@@ -24,7 +23,6 @@ class TestField(TestCase): | |||
24 | 23 | ||
25 | 24 | ||
26 | class TestModelMetaClass(TestCase): | 25 | class TestModelMetaClass(TestCase): |
27 | |||
28 | class TestModel(metaclass=m.ModelMetaClass): | 26 | class TestModel(metaclass=m.ModelMetaClass): |
29 | 27 | ||
30 | foo = "bar" | 28 | foo = "bar" |
@@ -40,7 +38,6 @@ class TestModelMetaClass(TestCase): | |||
40 | 38 | ||
41 | 39 | ||
42 | class TestDateField(TestCase): | 40 | class TestDateField(TestCase): |
43 | |||
44 | class SampleModel(m.PandoraModel): | 41 | class SampleModel(m.PandoraModel): |
45 | 42 | ||
46 | date_field = m.DateField("foo") | 43 | date_field = m.DateField("foo") |
@@ -57,34 +54,26 @@ class TestDateField(TestCase): | |||
57 | 54 | ||
58 | 55 | ||
59 | class TestAdditionalUrlField(TestCase): | 56 | class TestAdditionalUrlField(TestCase): |
60 | |||
61 | def test_single_url(self): | 57 | def test_single_url(self): |
62 | dummy_data = { | 58 | dummy_data = {"_paramAdditionalUrls": ["foo"]} |
63 | '_paramAdditionalUrls': ['foo'] | ||
64 | } | ||
65 | 59 | ||
66 | field = plm.AdditionalUrlField("additionalAudioUrl") | 60 | field = plm.AdditionalUrlField("additionalAudioUrl") |
67 | 61 | ||
68 | ret = field.formatter(None, dummy_data, 'test') | 62 | ret = field.formatter(None, dummy_data, "test") |
69 | 63 | ||
70 | self.assertEqual(ret, {'foo': 'test'}) | 64 | self.assertEqual(ret, {"foo": "test"}) |
71 | 65 | ||
72 | def test_multiple_urls(self): | 66 | def test_multiple_urls(self): |
73 | dummy_data = { | 67 | dummy_data = {"_paramAdditionalUrls": ["abc", "def",]} |
74 | '_paramAdditionalUrls': [ | ||
75 | 'abc', | ||
76 | 'def', | ||
77 | ] | ||
78 | } | ||
79 | 68 | ||
80 | field = plm.AdditionalUrlField("additionalAudioUrl") | 69 | field = plm.AdditionalUrlField("additionalAudioUrl") |
81 | 70 | ||
82 | ret = field.formatter(None, dummy_data, ['foo', 'bar']) | 71 | ret = field.formatter(None, dummy_data, ["foo", "bar"]) |
83 | 72 | ||
84 | expected = { | 73 | expected = { |
85 | 'abc': 'foo', | 74 | "abc": "foo", |
86 | 'def': 'bar', | 75 | "def": "bar", |
87 | } | 76 | } |
88 | 77 | ||
89 | self.assertEqual(ret, expected) | 78 | self.assertEqual(ret, expected) |
90 | 79 | ||
@@ -99,7 +88,6 @@ class TestPandoraModel(TestCase): | |||
99 | } | 88 | } |
100 | 89 | ||
101 | class TestModel(m.PandoraModel): | 90 | class TestModel(m.PandoraModel): |
102 | |||
103 | class SubModel(m.PandoraModel): | 91 | class SubModel(m.PandoraModel): |
104 | 92 | ||
105 | field1 = m.Field("field1") | 93 | field1 = m.Field("field1") |
@@ -116,7 +104,6 @@ class TestPandoraModel(TestCase): | |||
116 | pass | 104 | pass |
117 | 105 | ||
118 | class ExtraReprModel(m.PandoraModel): | 106 | class ExtraReprModel(m.PandoraModel): |
119 | |||
120 | def __repr__(self): | 107 | def __repr__(self): |
121 | return self._base_repr("Foo") | 108 | return self._base_repr("Foo") |
122 | 109 | ||
@@ -153,9 +140,11 @@ class TestPandoraModel(TestCase): | |||
153 | self.assertEqual("a string", result[1].field1) | 140 | self.assertEqual("a string", result[1].field1) |
154 | 141 | ||
155 | def test_repr(self): | 142 | def test_repr(self): |
156 | expected = ("TestModel(field1='a string', field2=['test2'], field3=42," | 143 | expected = ( |
157 | " field4=SubModel(field1='foo'), " | 144 | "TestModel(field1='a string', field2=['test2'], field3=42," |
158 | "field5=[SubModel(field1='foo'), SubModel(field1='bar')])") | 145 | " field4=SubModel(field1='foo'), " |
146 | "field5=[SubModel(field1='foo'), SubModel(field1='bar')])" | ||
147 | ) | ||
159 | result = self.TestModel.from_json(None, self.JSON_DATA) | 148 | result = self.TestModel.from_json(None, self.JSON_DATA) |
160 | self.assertEqual(expected, repr(result)) | 149 | self.assertEqual(expected, repr(result)) |
161 | 150 | ||
@@ -179,12 +168,12 @@ class TestSubModel(m.PandoraModel): | |||
179 | class TestPandoraListModel(TestCase): | 168 | class TestPandoraListModel(TestCase): |
180 | 169 | ||
181 | JSON_DATA = { | 170 | JSON_DATA = { |
182 | "field1": 42, | 171 | "field1": 42, |
183 | "field2": [ | 172 | "field2": [ |
184 | {"idx": "foo", "fieldS1": "Foo"}, | 173 | {"idx": "foo", "fieldS1": "Foo"}, |
185 | {"idx": "bar", "fieldS1": "Bar"}, | 174 | {"idx": "bar", "fieldS1": "Bar"}, |
186 | ] | 175 | ], |
187 | } | 176 | } |
188 | 177 | ||
189 | class TestModel(m.PandoraListModel): | 178 | class TestModel(m.PandoraListModel): |
190 | 179 | ||
@@ -204,8 +193,10 @@ class TestPandoraListModel(TestCase): | |||
204 | self.assertEqual("Bar", self.result[1].fieldS1) | 193 | self.assertEqual("Bar", self.result[1].fieldS1) |
205 | 194 | ||
206 | def test_repr(self): | 195 | def test_repr(self): |
207 | expected = ("TestModel(field1=42, [TestSubModel(fieldS1='Foo', " | 196 | expected = ( |
208 | "idx='foo'), TestSubModel(fieldS1='Bar', idx='bar')])") | 197 | "TestModel(field1=42, [TestSubModel(fieldS1='Foo', " |
198 | "idx='foo'), TestSubModel(fieldS1='Bar', idx='bar')])" | ||
199 | ) | ||
209 | self.assertEqual(expected, repr(self.result)) | 200 | self.assertEqual(expected, repr(self.result)) |
210 | 201 | ||
211 | def test_indexed_model(self): | 202 | def test_indexed_model(self): |
@@ -232,17 +223,17 @@ class TestPandoraListModel(TestCase): | |||
232 | class TestPandoraDictListModel(TestCase): | 223 | class TestPandoraDictListModel(TestCase): |
233 | 224 | ||
234 | JSON_DATA = { | 225 | JSON_DATA = { |
235 | "field1": 42, | 226 | "field1": 42, |
236 | "fieldD1": [ | 227 | "fieldD1": [ |
237 | { | 228 | { |
238 | "dictKey": "Foobear", | 229 | "dictKey": "Foobear", |
239 | "listKey": [ | 230 | "listKey": [ |
240 | {"idx": "foo", "fieldS1": "Foo"}, | 231 | {"idx": "foo", "fieldS1": "Foo"}, |
241 | {"idx": "bar", "fieldS1": "Bar"}, | 232 | {"idx": "bar", "fieldS1": "Bar"}, |
242 | ] | 233 | ], |
243 | } | 234 | } |
244 | ] | 235 | ], |
245 | } | 236 | } |
246 | 237 | ||
247 | class TestModel(m.PandoraDictListModel): | 238 | class TestModel(m.PandoraDictListModel): |
248 | 239 | ||
@@ -266,9 +257,11 @@ class TestPandoraDictListModel(TestCase): | |||
266 | self.assertEqual("bar", self.result["Foobear"][1].idx) | 257 | self.assertEqual("bar", self.result["Foobear"][1].idx) |
267 | 258 | ||
268 | def test_repr(self): | 259 | def test_repr(self): |
269 | expected = ("TestModel(field1=42, {'Foobear': " | 260 | expected = ( |
270 | "[TestSubModel(fieldS1='Foo', idx='foo'), " | 261 | "TestModel(field1=42, {'Foobear': " |
271 | "TestSubModel(fieldS1='Bar', idx='bar')]})") | 262 | "[TestSubModel(fieldS1='Foo', idx='foo'), " |
263 | "TestSubModel(fieldS1='Bar', idx='bar')]})" | ||
264 | ) | ||
272 | self.assertEqual(expected, repr(self.result)) | 265 | self.assertEqual(expected, repr(self.result)) |
273 | 266 | ||
274 | 267 | ||
@@ -320,7 +313,6 @@ class TestPlaylistItemModel(TestCase): | |||
320 | 313 | ||
321 | 314 | ||
322 | class TestPlaylistModel(TestCase): | 315 | class TestPlaylistModel(TestCase): |
323 | |||
324 | def setUp(self): | 316 | def setUp(self): |
325 | self.client = Mock() | 317 | self.client = Mock() |
326 | self.playlist = plm.PlaylistModel(self.client) | 318 | self.playlist = plm.PlaylistModel(self.client) |
@@ -354,47 +346,47 @@ class TestPlaylistModel(TestCase): | |||
354 | class TestAdItem(TestCase): | 346 | class TestAdItem(TestCase): |
355 | 347 | ||
356 | JSON_DATA = { | 348 | JSON_DATA = { |
357 | 'audioUrlMap': { | 349 | "audioUrlMap": { |
358 | 'mediumQuality': { | 350 | "mediumQuality": { |
359 | 'audioUrl': 'med_url_mock', | 351 | "audioUrl": "med_url_mock", |
360 | 'bitrate': '64', | 352 | "bitrate": "64", |
361 | 'protocol': 'http', | 353 | "protocol": "http", |
362 | 'encoding': 'aacplus' | 354 | "encoding": "aacplus", |
363 | }, | 355 | }, |
364 | 'highQuality': { | 356 | "highQuality": { |
365 | 'audioUrl': 'high_url_mock', | 357 | "audioUrl": "high_url_mock", |
366 | 'bitrate': '64', | 358 | "bitrate": "64", |
367 | 'protocol': 'http', | 359 | "protocol": "http", |
368 | 'encoding': 'aacplus' | 360 | "encoding": "aacplus", |
361 | }, | ||
362 | "lowQuality": { | ||
363 | "audioUrl": "low_url_mock", | ||
364 | "bitrate": "32", | ||
365 | "protocol": "http", | ||
366 | "encoding": "aacplus", | ||
369 | }, | 367 | }, |
370 | 'lowQuality': { | ||
371 | 'audioUrl': 'low_url_mock', | ||
372 | 'bitrate': '32', | ||
373 | 'protocol': 'http', | ||
374 | 'encoding': 'aacplus' | ||
375 | } | ||
376 | }, | 368 | }, |
377 | 'clickThroughUrl': 'click_url_mock', | 369 | "clickThroughUrl": "click_url_mock", |
378 | 'imageUrl': 'img_url_mock', | 370 | "imageUrl": "img_url_mock", |
379 | 'companyName': '', | 371 | "companyName": "", |
380 | 'title': '', | 372 | "title": "", |
381 | 'trackGain': '0.0', | 373 | "trackGain": "0.0", |
382 | 'adTrackingTokens': ['token_1_mock', 'token_2_mock'] | 374 | "adTrackingTokens": ["token_1_mock", "token_2_mock"], |
383 | } | 375 | } |
384 | 376 | ||
385 | def setUp(self): | 377 | def setUp(self): |
386 | api_client_mock = Mock(spec=APIClient) | 378 | api_client_mock = Mock(spec=APIClient) |
387 | api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY | 379 | api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY |
388 | self.result = am.AdItem.from_json(api_client_mock, self.JSON_DATA) | 380 | self.result = am.AdItem.from_json(api_client_mock, self.JSON_DATA) |
389 | self.result.station_id = 'station_id_mock' | 381 | self.result.station_id = "station_id_mock" |
390 | self.result.ad_token = 'token_mock' | 382 | self.result.ad_token = "token_mock" |
391 | 383 | ||
392 | def test_is_ad_is_true(self): | 384 | def test_is_ad_is_true(self): |
393 | assert self.result.is_ad is True | 385 | assert self.result.is_ad is True |
394 | 386 | ||
395 | def test_register_ad(self): | 387 | def test_register_ad(self): |
396 | self.result._api_client.register_ad = Mock() | 388 | self.result._api_client.register_ad = Mock() |
397 | self.result.register_ad('id_mock') | 389 | self.result.register_ad("id_mock") |
398 | 390 | ||
399 | assert self.result._api_client.register_ad.called | 391 | assert self.result._api_client.register_ad.called |
400 | 392 | ||
@@ -403,12 +395,12 @@ class TestAdItem(TestCase): | |||
403 | self.result.tracking_tokens = [] | 395 | self.result.tracking_tokens = [] |
404 | self.result._api_client.register_ad = Mock(spec=am.AdItem) | 396 | self.result._api_client.register_ad = Mock(spec=am.AdItem) |
405 | 397 | ||
406 | self.result.register_ad('id_mock') | 398 | self.result.register_ad("id_mock") |
407 | 399 | ||
408 | assert self.result._api_client.register_ad.called | 400 | assert self.result._api_client.register_ad.called |
409 | 401 | ||
410 | def test_prepare_playback(self): | 402 | def test_prepare_playback(self): |
411 | with patch.object(plm.PlaylistModel, 'prepare_playback') as super_mock: | 403 | with patch.object(plm.PlaylistModel, "prepare_playback") as super_mock: |
412 | 404 | ||
413 | self.result.register_ad = Mock() | 405 | self.result.register_ad = Mock() |
414 | self.result.prepare_playback() | 406 | self.result.prepare_playback() |
@@ -416,21 +408,26 @@ class TestAdItem(TestCase): | |||
416 | assert super_mock.called | 408 | assert super_mock.called |
417 | 409 | ||
418 | def test_prepare_playback_raises_paramater_missing(self): | 410 | def test_prepare_playback_raises_paramater_missing(self): |
419 | with patch.object(plm.PlaylistModel, 'prepare_playback') as super_mock: | 411 | with patch.object(plm.PlaylistModel, "prepare_playback") as super_mock: |
420 | 412 | ||
421 | self.result.register_ad = Mock(side_effect=ParameterMissing( | 413 | self.result.register_ad = Mock( |
422 | 'No ad tracking tokens provided for registration.') | 414 | side_effect=ParameterMissing( |
423 | ) | 415 | "No ad tracking tokens provided for registration." |
416 | ) | ||
417 | ) | ||
424 | self.assertRaises(ParameterMissing, self.result.prepare_playback) | 418 | self.assertRaises(ParameterMissing, self.result.prepare_playback) |
425 | assert self.result.register_ad.called | 419 | assert self.result.register_ad.called |
426 | assert not super_mock.called | 420 | assert not super_mock.called |
427 | 421 | ||
428 | def test_prepare_playback_handles_paramater_missing_if_no_tokens(self): | 422 | def test_prepare_playback_handles_paramater_missing_if_no_tokens(self): |
429 | with patch.object(plm.PlaylistModel, 'prepare_playback') as super_mock: | 423 | with patch.object(plm.PlaylistModel, "prepare_playback") as super_mock: |
430 | 424 | ||
431 | self.result.tracking_tokens = [] | 425 | self.result.tracking_tokens = [] |
432 | self.result.register_ad = Mock(side_effect=ParameterMissing( | 426 | self.result.register_ad = Mock( |
433 | 'No ad tracking tokens provided for registration.')) | 427 | side_effect=ParameterMissing( |
428 | "No ad tracking tokens provided for registration." | ||
429 | ) | ||
430 | ) | ||
434 | self.result.prepare_playback() | 431 | self.result.prepare_playback() |
435 | assert self.result.register_ad.called | 432 | assert self.result.register_ad.called |
436 | assert super_mock.called | 433 | assert super_mock.called |
@@ -449,43 +446,45 @@ class TestSearchResultItem(TestCase): | |||
449 | "artistName": "artist_name_mock", | 446 | "artistName": "artist_name_mock", |
450 | "musicToken": "S0000000", | 447 | "musicToken": "S0000000", |
451 | "songName": "song_name_mock", | 448 | "songName": "song_name_mock", |
452 | "score": 100 | 449 | "score": 100, |
453 | } | 450 | } |
454 | 451 | ||
455 | ARTIST_JSON_DATA = { | 452 | ARTIST_JSON_DATA = { |
456 | "artistName": "artist_name_mock", | 453 | "artistName": "artist_name_mock", |
457 | "musicToken": "R0000000", | 454 | "musicToken": "R0000000", |
458 | "likelyMatch": False, | 455 | "likelyMatch": False, |
459 | "score": 100 | 456 | "score": 100, |
460 | } | 457 | } |
461 | 458 | ||
462 | COMPOSER_JSON_DATA = { | 459 | COMPOSER_JSON_DATA = { |
463 | "artistName": "composer_name_mock", | 460 | "artistName": "composer_name_mock", |
464 | "musicToken": "C0000000", | 461 | "musicToken": "C0000000", |
465 | "likelyMatch": False, | 462 | "likelyMatch": False, |
466 | "score": 100 | 463 | "score": 100, |
467 | } | 464 | } |
468 | 465 | ||
469 | GENRE_JSON_DATA = { | 466 | GENRE_JSON_DATA = { |
470 | "stationName": "station_name_mock", | 467 | "stationName": "station_name_mock", |
471 | "musicToken": "G0000000", | 468 | "musicToken": "G0000000", |
472 | "score": 100 | 469 | "score": 100, |
473 | } | 470 | } |
474 | 471 | ||
475 | UNKNOWN_JSON_DATA = { | 472 | UNKNOWN_JSON_DATA = { |
476 | "stationName": "unknown_name_mock", | 473 | "stationName": "unknown_name_mock", |
477 | "musicToken": "U0000000", | 474 | "musicToken": "U0000000", |
478 | "score": 100 | 475 | "score": 100, |
479 | } | 476 | } |
480 | 477 | ||
481 | def setUp(self): | 478 | def setUp(self): |
482 | self.api_client_mock = Mock(spec=APIClient) | 479 | self.api_client_mock = Mock(spec=APIClient) |
483 | self.api_client_mock.default_audio_quality = \ | 480 | self.api_client_mock.default_audio_quality = ( |
484 | APIClient.HIGH_AUDIO_QUALITY | 481 | APIClient.HIGH_AUDIO_QUALITY |
482 | ) | ||
485 | 483 | ||
486 | def test_is_song(self): | 484 | def test_is_song(self): |
487 | result = sm.SearchResultItem.from_json( | 485 | result = sm.SearchResultItem.from_json( |
488 | self.api_client_mock, self.SONG_JSON_DATA) | 486 | self.api_client_mock, self.SONG_JSON_DATA |
487 | ) | ||
489 | assert result.is_song | 488 | assert result.is_song |
490 | assert not result.is_artist | 489 | assert not result.is_artist |
491 | assert not result.is_composer | 490 | assert not result.is_composer |
@@ -493,7 +492,8 @@ class TestSearchResultItem(TestCase): | |||
493 | 492 | ||
494 | def test_is_artist(self): | 493 | def test_is_artist(self): |
495 | result = sm.SearchResultItem.from_json( | 494 | result = sm.SearchResultItem.from_json( |
496 | self.api_client_mock, self.ARTIST_JSON_DATA) | 495 | self.api_client_mock, self.ARTIST_JSON_DATA |
496 | ) | ||
497 | assert not result.is_song | 497 | assert not result.is_song |
498 | assert result.is_artist | 498 | assert result.is_artist |
499 | assert not result.is_composer | 499 | assert not result.is_composer |
@@ -501,7 +501,8 @@ class TestSearchResultItem(TestCase): | |||
501 | 501 | ||
502 | def test_is_composer(self): | 502 | def test_is_composer(self): |
503 | result = sm.SearchResultItem.from_json( | 503 | result = sm.SearchResultItem.from_json( |
504 | self.api_client_mock, self.COMPOSER_JSON_DATA) | 504 | self.api_client_mock, self.COMPOSER_JSON_DATA |
505 | ) | ||
505 | assert not result.is_song | 506 | assert not result.is_song |
506 | assert not result.is_artist | 507 | assert not result.is_artist |
507 | assert result.is_composer | 508 | assert result.is_composer |
@@ -509,7 +510,8 @@ class TestSearchResultItem(TestCase): | |||
509 | 510 | ||
510 | def test_is_genre_station(self): | 511 | def test_is_genre_station(self): |
511 | result = sm.SearchResultItem.from_json( | 512 | result = sm.SearchResultItem.from_json( |
512 | self.api_client_mock, self.GENRE_JSON_DATA) | 513 | self.api_client_mock, self.GENRE_JSON_DATA |
514 | ) | ||
513 | assert not result.is_song | 515 | assert not result.is_song |
514 | assert not result.is_artist | 516 | assert not result.is_artist |
515 | assert not result.is_composer | 517 | assert not result.is_composer |
@@ -518,7 +520,8 @@ class TestSearchResultItem(TestCase): | |||
518 | def test_fails_if_unknown(self): | 520 | def test_fails_if_unknown(self): |
519 | with self.assertRaises(NotImplementedError): | 521 | with self.assertRaises(NotImplementedError): |
520 | sm.SearchResultItem.from_json( | 522 | sm.SearchResultItem.from_json( |
521 | self.api_client_mock, self.UNKNOWN_JSON_DATA) | 523 | self.api_client_mock, self.UNKNOWN_JSON_DATA |
524 | ) | ||
522 | 525 | ||
523 | def test_interface(self): | 526 | def test_interface(self): |
524 | result = sm.SearchResultItem(self.api_client_mock) | 527 | result = sm.SearchResultItem(self.api_client_mock) |
@@ -533,44 +536,51 @@ class TestArtistSearchResultItem(TestCase): | |||
533 | "artistName": "artist_name_mock", | 536 | "artistName": "artist_name_mock", |
534 | "musicToken": "R0000000", | 537 | "musicToken": "R0000000", |
535 | "likelyMatch": False, | 538 | "likelyMatch": False, |
536 | "score": 100 | 539 | "score": 100, |
537 | } | 540 | } |
538 | 541 | ||
539 | COMPOSER_JSON_DATA = { | 542 | COMPOSER_JSON_DATA = { |
540 | "artistName": "composer_name_mock", | 543 | "artistName": "composer_name_mock", |
541 | "musicToken": "C0000000", | 544 | "musicToken": "C0000000", |
542 | "likelyMatch": False, | 545 | "likelyMatch": False, |
543 | "score": 100 | 546 | "score": 100, |
544 | } | 547 | } |
545 | 548 | ||
546 | def setUp(self): | 549 | def setUp(self): |
547 | self.api_client_mock = Mock(spec=APIClient) | 550 | self.api_client_mock = Mock(spec=APIClient) |
548 | self.api_client_mock.default_audio_quality = \ | 551 | self.api_client_mock.default_audio_quality = ( |
549 | APIClient.HIGH_AUDIO_QUALITY | 552 | APIClient.HIGH_AUDIO_QUALITY |
553 | ) | ||
550 | 554 | ||
551 | def test_repr(self): | 555 | def test_repr(self): |
552 | result = sm.SearchResultItem.from_json( | 556 | result = sm.SearchResultItem.from_json( |
553 | self.api_client_mock, self.ARTIST_JSON_DATA) | 557 | self.api_client_mock, self.ARTIST_JSON_DATA |
558 | ) | ||
554 | expected = ( | 559 | expected = ( |
555 | "ArtistSearchResultItem(artist='artist_name_mock', " | 560 | "ArtistSearchResultItem(artist='artist_name_mock', " |
556 | "likely_match=False, score=100, token='R0000000')") | 561 | "likely_match=False, score=100, token='R0000000')" |
562 | ) | ||
557 | self.assertEqual(expected, repr(result)) | 563 | self.assertEqual(expected, repr(result)) |
558 | 564 | ||
559 | result = sm.SearchResultItem.from_json( | 565 | result = sm.SearchResultItem.from_json( |
560 | self.api_client_mock, self.COMPOSER_JSON_DATA) | 566 | self.api_client_mock, self.COMPOSER_JSON_DATA |
567 | ) | ||
561 | expected = ( | 568 | expected = ( |
562 | "ArtistSearchResultItem(artist='composer_name_mock', " | 569 | "ArtistSearchResultItem(artist='composer_name_mock', " |
563 | "likely_match=False, score=100, token='C0000000')") | 570 | "likely_match=False, score=100, token='C0000000')" |
571 | ) | ||
564 | self.assertEqual(expected, repr(result)) | 572 | self.assertEqual(expected, repr(result)) |
565 | 573 | ||
566 | def test_create_station(self): | 574 | def test_create_station(self): |
567 | result = sm.SearchResultItem.from_json( | 575 | result = sm.SearchResultItem.from_json( |
568 | self.api_client_mock, self.ARTIST_JSON_DATA) | 576 | self.api_client_mock, self.ARTIST_JSON_DATA |
577 | ) | ||
569 | result._api_client.create_station = Mock() | 578 | result._api_client.create_station = Mock() |
570 | 579 | ||
571 | result.create_station() | 580 | result.create_station() |
572 | result._api_client.create_station.assert_called_with( | 581 | result._api_client.create_station.assert_called_with( |
573 | artist_token=result.token) | 582 | artist_token=result.token |
583 | ) | ||
574 | 584 | ||
575 | 585 | ||
576 | class TestSongSearchResultItem(TestCase): | 586 | class TestSongSearchResultItem(TestCase): |
@@ -579,30 +589,35 @@ class TestSongSearchResultItem(TestCase): | |||
579 | "artistName": "artist_name_mock", | 589 | "artistName": "artist_name_mock", |
580 | "musicToken": "S0000000", | 590 | "musicToken": "S0000000", |
581 | "songName": "song_name_mock", | 591 | "songName": "song_name_mock", |
582 | "score": 100 | 592 | "score": 100, |
583 | } | 593 | } |
584 | 594 | ||
585 | def setUp(self): | 595 | def setUp(self): |
586 | self.api_client_mock = Mock(spec=APIClient) | 596 | self.api_client_mock = Mock(spec=APIClient) |
587 | self.api_client_mock.default_audio_quality = \ | 597 | self.api_client_mock.default_audio_quality = ( |
588 | APIClient.HIGH_AUDIO_QUALITY | 598 | APIClient.HIGH_AUDIO_QUALITY |
599 | ) | ||
589 | 600 | ||
590 | def test_repr(self): | 601 | def test_repr(self): |
591 | result = sm.SearchResultItem.from_json( | 602 | result = sm.SearchResultItem.from_json( |
592 | self.api_client_mock, self.SONG_JSON_DATA) | 603 | self.api_client_mock, self.SONG_JSON_DATA |
604 | ) | ||
593 | expected = ( | 605 | expected = ( |
594 | "SongSearchResultItem(artist='artist_name_mock', score=100, " | 606 | "SongSearchResultItem(artist='artist_name_mock', score=100, " |
595 | "song_name='song_name_mock', token='S0000000')") | 607 | "song_name='song_name_mock', token='S0000000')" |
608 | ) | ||
596 | self.assertEqual(expected, repr(result)) | 609 | self.assertEqual(expected, repr(result)) |
597 | 610 | ||
598 | def test_create_station(self): | 611 | def test_create_station(self): |
599 | result = sm.SearchResultItem.from_json( | 612 | result = sm.SearchResultItem.from_json( |
600 | self.api_client_mock, self.SONG_JSON_DATA) | 613 | self.api_client_mock, self.SONG_JSON_DATA |
614 | ) | ||
601 | result._api_client.create_station = Mock() | 615 | result._api_client.create_station = Mock() |
602 | 616 | ||
603 | result.create_station() | 617 | result.create_station() |
604 | result._api_client.create_station.assert_called_with( | 618 | result._api_client.create_station.assert_called_with( |
605 | track_token=result.token) | 619 | track_token=result.token |
620 | ) | ||
606 | 621 | ||
607 | 622 | ||
608 | class TestGenreStationSearchResultItem(TestCase): | 623 | class TestGenreStationSearchResultItem(TestCase): |
@@ -610,61 +625,69 @@ class TestGenreStationSearchResultItem(TestCase): | |||
610 | GENRE_JSON_DATA = { | 625 | GENRE_JSON_DATA = { |
611 | "stationName": "station_name_mock", | 626 | "stationName": "station_name_mock", |
612 | "musicToken": "G0000000", | 627 | "musicToken": "G0000000", |
613 | "score": 100 | 628 | "score": 100, |
614 | } | 629 | } |
615 | 630 | ||
616 | def setUp(self): | 631 | def setUp(self): |
617 | self.api_client_mock = Mock(spec=APIClient) | 632 | self.api_client_mock = Mock(spec=APIClient) |
618 | self.api_client_mock.default_audio_quality = \ | 633 | self.api_client_mock.default_audio_quality = ( |
619 | APIClient.HIGH_AUDIO_QUALITY | 634 | APIClient.HIGH_AUDIO_QUALITY |
635 | ) | ||
620 | 636 | ||
621 | def test_repr(self): | 637 | def test_repr(self): |
622 | result = sm.SearchResultItem.from_json( | 638 | result = sm.SearchResultItem.from_json( |
623 | self.api_client_mock, self.GENRE_JSON_DATA) | 639 | self.api_client_mock, self.GENRE_JSON_DATA |
640 | ) | ||
624 | expected = ( | 641 | expected = ( |
625 | "GenreStationSearchResultItem(score=100, " | 642 | "GenreStationSearchResultItem(score=100, " |
626 | "station_name='station_name_mock', token='G0000000')") | 643 | "station_name='station_name_mock', token='G0000000')" |
644 | ) | ||
627 | self.assertEqual(expected, repr(result)) | 645 | self.assertEqual(expected, repr(result)) |
628 | 646 | ||
629 | def test_create_station(self): | 647 | def test_create_station(self): |
630 | result = sm.SearchResultItem.from_json( | 648 | result = sm.SearchResultItem.from_json( |
631 | self.api_client_mock, self.GENRE_JSON_DATA) | 649 | self.api_client_mock, self.GENRE_JSON_DATA |
650 | ) | ||
632 | result._api_client.create_station = Mock() | 651 | result._api_client.create_station = Mock() |
633 | 652 | ||
634 | result.create_station() | 653 | result.create_station() |
635 | result._api_client.create_station.assert_called_with( | 654 | result._api_client.create_station.assert_called_with( |
636 | search_token=result.token) | 655 | search_token=result.token |
656 | ) | ||
637 | 657 | ||
638 | 658 | ||
639 | class TestSearchResult(TestCase): | 659 | class TestSearchResult(TestCase): |
640 | 660 | ||
641 | JSON_DATA = { | 661 | JSON_DATA = { |
642 | 'nearMatchesAvailable': True, | 662 | "nearMatchesAvailable": True, |
643 | 'explanation': '', | 663 | "explanation": "", |
644 | 'songs': [{ | 664 | "songs": [ |
645 | 'artistName': 'song_artist_mock', | 665 | { |
646 | 'musicToken': 'S0000000', | 666 | "artistName": "song_artist_mock", |
647 | 'songName': 'song_name_mock', | 667 | "musicToken": "S0000000", |
648 | 'score': 100 | 668 | "songName": "song_name_mock", |
649 | }], | 669 | "score": 100, |
650 | 'artists': [{ | 670 | } |
651 | 'artistName': 'artist_mock', | 671 | ], |
652 | 'musicToken': 'R000000', | 672 | "artists": [ |
653 | 'likelyMatch': False, | 673 | { |
654 | 'score': 80 | 674 | "artistName": "artist_mock", |
655 | }], | 675 | "musicToken": "R000000", |
656 | 'genreStations': [{ | 676 | "likelyMatch": False, |
657 | 'musicToken': 'G0000', | 677 | "score": 80, |
658 | 'stationName': 'station_mock', | 678 | } |
659 | 'score': 50 | 679 | ], |
660 | }] | 680 | "genreStations": [ |
681 | {"musicToken": "G0000", "stationName": "station_mock", "score": 50} | ||
682 | ], | ||
661 | } | 683 | } |
662 | 684 | ||
663 | def setUp(self): | 685 | def setUp(self): |
664 | api_client_mock = Mock(spec=APIClient) | 686 | api_client_mock = Mock(spec=APIClient) |
665 | api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY | 687 | api_client_mock.default_audio_quality = APIClient.HIGH_AUDIO_QUALITY |
666 | self.result = sm.SearchResult.from_json( | 688 | self.result = sm.SearchResult.from_json( |
667 | api_client_mock, self.JSON_DATA) | 689 | api_client_mock, self.JSON_DATA |
690 | ) | ||
668 | 691 | ||
669 | def test_repr(self): | 692 | def test_repr(self): |
670 | expected = ( | 693 | expected = ( |
@@ -676,7 +699,8 @@ class TestSearchResult(TestCase): | |||
676 | "nearest_matches_available=True, " | 699 | "nearest_matches_available=True, " |
677 | "songs=[SongSearchResultItem(artist='song_artist_mock', " | 700 | "songs=[SongSearchResultItem(artist='song_artist_mock', " |
678 | "score=100, song_name='song_name_mock', " | 701 | "score=100, song_name='song_name_mock', " |
679 | "token='S0000000')])") | 702 | "token='S0000000')])" |
703 | ) | ||
680 | self.assertEqual(expected, repr(self.result)) | 704 | self.assertEqual(expected, repr(self.result)) |
681 | 705 | ||
682 | 706 | ||
@@ -684,9 +708,7 @@ class TestGenreStationList(TestCase): | |||
684 | 708 | ||
685 | TEST_DATA = { | 709 | TEST_DATA = { |
686 | "checksum": "bar", | 710 | "checksum": "bar", |
687 | "categories": [ | 711 | "categories": [{"categoryName": "foo", "stations": []},], |
688 | {"categoryName": "foo", "stations": []}, | ||
689 | ] | ||
690 | } | 712 | } |
691 | 713 | ||
692 | def test_has_changed(self): | 714 | def test_has_changed(self): |
@@ -706,7 +728,8 @@ class TestGenreStation(TestCase): | |||
706 | genre_station = stm.GenreStation.from_json(api_client, self.TEST_DATA) | 728 | genre_station = stm.GenreStation.from_json(api_client, self.TEST_DATA) |
707 | 729 | ||
708 | with self.assertRaisesRegex( | 730 | with self.assertRaisesRegex( |
709 | NotImplementedError, "Genre stations do not have playlists.*"): | 731 | NotImplementedError, "Genre stations do not have playlists.*" |
732 | ): | ||
710 | genre_station.get_playlist() | 733 | genre_station.get_playlist() |
711 | 734 | ||
712 | 735 | ||
@@ -750,7 +773,6 @@ class TestBookmark(TestCase): | |||
750 | 773 | ||
751 | 774 | ||
752 | class TestPandoraType(TestCase): | 775 | class TestPandoraType(TestCase): |
753 | |||
754 | def test_it_can_be_built_from_a_model(self): | 776 | def test_it_can_be_built_from_a_model(self): |
755 | pt = plm.PandoraType.from_model(None, "TR") | 777 | pt = plm.PandoraType.from_model(None, "TR") |
756 | self.assertIs(plm.PandoraType.TRACK, pt) | 778 | self.assertIs(plm.PandoraType.TRACK, pt) |
@@ -765,7 +787,6 @@ class TestPandoraType(TestCase): | |||
765 | 787 | ||
766 | 788 | ||
767 | class TestSyntheticField(TestCase): | 789 | class TestSyntheticField(TestCase): |
768 | |||
769 | def test_interface(self): | 790 | def test_interface(self): |
770 | sf = m.SyntheticField(field="foo") | 791 | sf = m.SyntheticField(field="foo") |
771 | 792 | ||