diff options
author | jcass <john.cass77@gmail.com> | 2015-10-30 09:06:10 +0200 |
---|---|---|
committer | Mike Crute <mcrute@gmail.com> | 2015-12-05 18:51:30 -0800 |
commit | 439ba17affe26dd172a0d0b1433e9210e6d6ad03 (patch) | |
tree | d62c96719c9c29ef8af3770b095e4063abd63b71 /tests | |
parent | 37bb7ed8810c4d0f670fb7eee574816acd34cc0a (diff) | |
download | pydora-439ba17affe26dd172a0d0b1433e9210e6d6ad03.tar.bz2 pydora-439ba17affe26dd172a0d0b1433e9210e6d6ad03.tar.xz pydora-439ba17affe26dd172a0d0b1433e9210e6d6ad03.zip |
Add helper function to concatenate dictionaries. Add test cases for ad support.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_pandora/test_client.py | 55 | ||||
-rw-r--r-- | tests/test_pandora/test_clientbuilder.py | 5 |
2 files changed, 56 insertions, 4 deletions
diff --git a/tests/test_pandora/test_client.py b/tests/test_pandora/test_client.py index cfeebb7..01fb9ae 100644 --- a/tests/test_pandora/test_client.py +++ b/tests/test_pandora/test_client.py | |||
@@ -1,9 +1,8 @@ | |||
1 | from unittest import TestCase | 1 | from unittest import TestCase |
2 | 2 | ||
3 | from pandora.client import BaseAPIClient | 3 | from pandora.client import APIClient, BaseAPIClient |
4 | from pandora.transport import APITransport | ||
5 | from pandora.errors import InvalidAuthToken | 4 | from pandora.errors import InvalidAuthToken |
6 | from pandora.py2compat import Mock, MagicMock, call | 5 | from pandora.py2compat import Mock, MagicMock, call, patch |
7 | 6 | ||
8 | 7 | ||
9 | class TestCallingAPIClient(TestCase): | 8 | class TestCallingAPIClient(TestCase): |
@@ -19,3 +18,53 @@ class TestCallingAPIClient(TestCase): | |||
19 | 18 | ||
20 | client._authenticate.assert_called_with() | 19 | client._authenticate.assert_called_with() |
21 | transport.assert_has_calls([call("method"), call("method")]) | 20 | transport.assert_has_calls([call("method"), call("method")]) |
21 | |||
22 | def test_get_params_dict_ad_support_enabled(self): | ||
23 | transport = Mock(side_effect=[InvalidAuthToken(), None]) | ||
24 | |||
25 | reg_dict = dict(x=1, y=2) | ||
26 | ad_dict = dict(z=3) | ||
27 | |||
28 | client = BaseAPIClient(transport, None, None, None, None, True) | ||
29 | result_dict = client.get_params_dict(reg_dict, ad_dict) | ||
30 | |||
31 | assert 'z' in result_dict | ||
32 | |||
33 | def test_get_params_dict_ad_support_disabled(self): | ||
34 | transport = Mock(side_effect=[InvalidAuthToken(), None]) | ||
35 | |||
36 | reg_dict = dict(x=1, y=2) | ||
37 | ad_dict = dict(z=3) | ||
38 | |||
39 | client = BaseAPIClient(transport, None, None, None, None, False) | ||
40 | result_dict = client.get_params_dict(reg_dict, ad_dict) | ||
41 | |||
42 | assert not 'z' in result_dict | ||
43 | |||
44 | def test_ad_support_enabled_parameters(self): | ||
45 | with patch.object(APIClient, '__call__') as playlist_mock: | ||
46 | transport = Mock(side_effect=[InvalidAuthToken(), None]) | ||
47 | |||
48 | client = APIClient(transport, None, None, None, None, True) | ||
49 | client._authenticate = Mock() | ||
50 | |||
51 | client.get_playlist('mock_token') | ||
52 | |||
53 | playlist_mock.assert_has_calls([call("station.getPlaylist", | ||
54 | audioAdPodCapable=True, | ||
55 | includeTrackLength=True, | ||
56 | stationToken='mock_token', | ||
57 | xplatformAdCapable=True)]) | ||
58 | |||
59 | def test_ad_support_disabled_parameters(self): | ||
60 | with patch.object(APIClient, '__call__') as playlist_mock: | ||
61 | transport = Mock(side_effect=[InvalidAuthToken(), None]) | ||
62 | |||
63 | client = APIClient(transport, None, None, None, None) | ||
64 | client._authenticate = Mock() | ||
65 | |||
66 | client.get_playlist('mock_token') | ||
67 | |||
68 | playlist_mock.assert_has_calls([call("station.getPlaylist", | ||
69 | includeTrackLength=True, | ||
70 | stationToken='mock_token')]) | ||
diff --git a/tests/test_pandora/test_clientbuilder.py b/tests/test_pandora/test_clientbuilder.py index 6c65cd1..1882c53 100644 --- a/tests/test_pandora/test_clientbuilder.py +++ b/tests/test_pandora/test_clientbuilder.py | |||
@@ -81,8 +81,8 @@ class TestSettingsDictBuilder(TestCase): | |||
81 | "PARTNER_PASSWORD": "pass", | 81 | "PARTNER_PASSWORD": "pass", |
82 | "DEVICE": "dev", | 82 | "DEVICE": "dev", |
83 | "PROXY": "proxy.example.com", | 83 | "PROXY": "proxy.example.com", |
84 | "AD_SUPPORT_ENABLED": "test_ad_support", | ||
85 | "AUDIO_QUALITY": "high", | 84 | "AUDIO_QUALITY": "high", |
85 | "AD_SUPPORT_ENABLED": True, | ||
86 | "API_HOST": "example.com", | 86 | "API_HOST": "example.com", |
87 | }).build() | 87 | }).build() |
88 | 88 | ||
@@ -98,6 +98,8 @@ class TestSettingsDictBuilder(TestCase): | |||
98 | self.assertEqual(DEFAULT_API_HOST, client.transport.api_host) | 98 | self.assertEqual(DEFAULT_API_HOST, client.transport.api_host) |
99 | self.assertEqual(APIClient.MED_AUDIO_QUALITY, | 99 | self.assertEqual(APIClient.MED_AUDIO_QUALITY, |
100 | client.default_audio_quality) | 100 | client.default_audio_quality) |
101 | self.assertEqual(False, | ||
102 | client.ad_support_enabled) | ||
101 | 103 | ||
102 | def test_validate_client(self): | 104 | def test_validate_client(self): |
103 | client = TestSettingsDictBuilder._build_maximal() | 105 | client = TestSettingsDictBuilder._build_maximal() |
@@ -116,6 +118,7 @@ class TestSettingsDictBuilder(TestCase): | |||
116 | self.assertEqual(expected_proxies, client.transport._http.proxies) | 118 | self.assertEqual(expected_proxies, client.transport._http.proxies) |
117 | self.assertEqual("example.com", client.transport.api_host) | 119 | self.assertEqual("example.com", client.transport.api_host) |
118 | self.assertEqual("high", client.default_audio_quality) | 120 | self.assertEqual("high", client.default_audio_quality) |
121 | self.assertEqual(True, client.ad_support_enabled) | ||
119 | 122 | ||
120 | 123 | ||
121 | class TestFileBasedBuilder(TestCase): | 124 | class TestFileBasedBuilder(TestCase): |