diff options
author | jcass <john.cass77@gmail.com> | 2015-12-21 07:46:41 +0200 |
---|---|---|
committer | jcass <john.cass77@gmail.com> | 2015-12-21 07:46:41 +0200 |
commit | cb531526f92ed83f9a181d3cfbc811af13d2934e (patch) | |
tree | 98c24b9767ccaeb0eacebf7fbdf4f0d8f418b2a6 /tests | |
parent | 4c2ac3d0246ff73bc68756ad1dd3648c1d51d30d (diff) | |
download | pydora-cb531526f92ed83f9a181d3cfbc811af13d2934e.tar.bz2 pydora-cb531526f92ed83f9a181d3cfbc811af13d2934e.tar.xz pydora-cb531526f92ed83f9a181d3cfbc811af13d2934e.zip |
Additional error checking and test cases for retrieving ad metadata.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_pandora/test_client.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py index 71435a4..e7ef87f 100644 --- a/tests/test_pandora/test_client.py +++ b/tests/test_pandora/test_client.py | |||
@@ -91,3 +91,47 @@ class TestGettingQualities(TestCase): | |||
91 | BaseAPIClient.MED_AUDIO_QUALITY] | 91 | BaseAPIClient.MED_AUDIO_QUALITY] |
92 | 92 | ||
93 | self.assertEqual(expected, result) | 93 | self.assertEqual(expected, result) |
94 | |||
95 | |||
96 | class TestGettingAds(TestCase): | ||
97 | |||
98 | mock_ad_metadata_result = { | ||
99 | 'audioUrlMap': { | ||
100 | 'mediumQuality': { | ||
101 | 'audioUrl': 'mock_med_url', 'bitrate': '64', 'protocol': 'http', 'encoding': 'aacplus' | ||
102 | }, | ||
103 | 'highQuality': { | ||
104 | 'audioUrl': 'mock_high_url', 'bitrate': '64', 'protocol': 'http', 'encoding': 'aacplus' | ||
105 | }, | ||
106 | 'lowQuality': { | ||
107 | 'audioUrl': 'mock_low_url', 'bitrate': '32', 'protocol': 'http', 'encoding': 'aacplus'}}, | ||
108 | 'clickThroughUrl': 'mock_click_url', | ||
109 | 'imageUrl': 'mock_img_url', | ||
110 | 'companyName': '', | ||
111 | 'title': '', | ||
112 | 'trackGain': '0.0', | ||
113 | 'adTrackingTokens': ['mock_token_1', 'mock_token_2'] | ||
114 | } | ||
115 | |||
116 | def test_get_ad_item_(self): | ||
117 | with patch.object(APIClient, '__call__', return_value=self.mock_ad_metadata_result) as ad_metadata_mock: | ||
118 | transport = Mock(side_effect=[InvalidAuthToken(), None]) | ||
119 | |||
120 | client = APIClient(transport, None, None, None, None) | ||
121 | client._authenticate = Mock() | ||
122 | |||
123 | ad_item = client.get_ad_item('mock_id', 'mock_token') | ||
124 | assert ad_item.station_id == 'mock_id' | ||
125 | |||
126 | ad_metadata_mock.assert_has_calls([call("ad.getAdMetadata", | ||
127 | adToken='mock_token', | ||
128 | returnAdTrackingTokens=True, | ||
129 | supportAudioAds=True)]) | ||
130 | |||
131 | def test_get_ad_item_with_no_station_id_specified_raises_exception(self): | ||
132 | transport = Mock(side_effect=[InvalidAuthToken(), None]) | ||
133 | |||
134 | client = APIClient(transport, None, None, None, None) | ||
135 | client.get_ad_metadata = Mock() | ||
136 | |||
137 | self.assertRaises(ValueError, client.get_ad_item, '', 'mock_token') | ||