diff options
Diffstat (limited to 'tests/test_pandora/test_clientbuilder.py')
-rw-r--r-- | tests/test_pandora/test_clientbuilder.py | 112 |
1 files changed, 59 insertions, 53 deletions
diff --git a/tests/test_pandora/test_clientbuilder.py b/tests/test_pandora/test_clientbuilder.py index af0e219..17a4036 100644 --- a/tests/test_pandora/test_clientbuilder.py +++ b/tests/test_pandora/test_clientbuilder.py | |||
@@ -8,7 +8,6 @@ from pandora.transport import DEFAULT_API_HOST | |||
8 | 8 | ||
9 | 9 | ||
10 | class TestTranslatingDict(TestCase): | 10 | class TestTranslatingDict(TestCase): |
11 | |||
12 | class TestDict(cb.TranslatingDict): | 11 | class TestDict(cb.TranslatingDict): |
13 | 12 | ||
14 | KEY_TRANSLATIONS = {"FOO": "BAR"} | 13 | KEY_TRANSLATIONS = {"FOO": "BAR"} |
@@ -62,29 +61,32 @@ class TestTranslatingDict(TestCase): | |||
62 | 61 | ||
63 | 62 | ||
64 | class TestSettingsDictBuilder(TestCase): | 63 | class TestSettingsDictBuilder(TestCase): |
65 | |||
66 | @classmethod | 64 | @classmethod |
67 | def _build_minimal(self): | 65 | def _build_minimal(self): |
68 | return cb.SettingsDictBuilder({ | 66 | return cb.SettingsDictBuilder( |
69 | "DECRYPTION_KEY": "blowfishkey", | 67 | { |
70 | "ENCRYPTION_KEY": "blowfishkey", | 68 | "DECRYPTION_KEY": "blowfishkey", |
71 | "PARTNER_USER": "user", | 69 | "ENCRYPTION_KEY": "blowfishkey", |
72 | "PARTNER_PASSWORD": "pass", | 70 | "PARTNER_USER": "user", |
73 | "DEVICE": "dev", | 71 | "PARTNER_PASSWORD": "pass", |
74 | }).build() | 72 | "DEVICE": "dev", |
73 | } | ||
74 | ).build() | ||
75 | 75 | ||
76 | @classmethod | 76 | @classmethod |
77 | def _build_maximal(self): | 77 | def _build_maximal(self): |
78 | return cb.SettingsDictBuilder({ | 78 | return cb.SettingsDictBuilder( |
79 | "DECRYPTION_KEY": "blowfishkey", | 79 | { |
80 | "ENCRYPTION_KEY": "blowfishkey", | 80 | "DECRYPTION_KEY": "blowfishkey", |
81 | "PARTNER_USER": "user", | 81 | "ENCRYPTION_KEY": "blowfishkey", |
82 | "PARTNER_PASSWORD": "pass", | 82 | "PARTNER_USER": "user", |
83 | "DEVICE": "dev", | 83 | "PARTNER_PASSWORD": "pass", |
84 | "PROXY": "proxy.example.com", | 84 | "DEVICE": "dev", |
85 | "AUDIO_QUALITY": "high", | 85 | "PROXY": "proxy.example.com", |
86 | "API_HOST": "example.com", | 86 | "AUDIO_QUALITY": "high", |
87 | }).build() | 87 | "API_HOST": "example.com", |
88 | } | ||
89 | ).build() | ||
88 | 90 | ||
89 | def test_building(self): | 91 | def test_building(self): |
90 | client = TestSettingsDictBuilder._build_minimal() | 92 | client = TestSettingsDictBuilder._build_minimal() |
@@ -97,14 +99,15 @@ class TestSettingsDictBuilder(TestCase): | |||
97 | self.assertEqual({}, client.transport._http.proxies) | 99 | self.assertEqual({}, client.transport._http.proxies) |
98 | self.assertEqual(DEFAULT_API_HOST, client.transport.api_host) | 100 | self.assertEqual(DEFAULT_API_HOST, client.transport.api_host) |
99 | self.assertEqual( | 101 | self.assertEqual( |
100 | APIClient.MED_AUDIO_QUALITY, client.default_audio_quality) | 102 | APIClient.MED_AUDIO_QUALITY, client.default_audio_quality |
103 | ) | ||
101 | 104 | ||
102 | def test_validate_client(self): | 105 | def test_validate_client(self): |
103 | client = TestSettingsDictBuilder._build_maximal() | 106 | client = TestSettingsDictBuilder._build_maximal() |
104 | expected_proxies = { | 107 | expected_proxies = { |
105 | "http": "proxy.example.com", | 108 | "http": "proxy.example.com", |
106 | "https": "proxy.example.com" | 109 | "https": "proxy.example.com", |
107 | } | 110 | } |
108 | 111 | ||
109 | self.assertIsNotNone(client.transport.cryptor.bf_in) | 112 | self.assertIsNotNone(client.transport.cryptor.bf_in) |
110 | self.assertIsNotNone(client.transport.cryptor.bf_out) | 113 | self.assertIsNotNone(client.transport.cryptor.bf_out) |
@@ -119,7 +122,6 @@ class TestSettingsDictBuilder(TestCase): | |||
119 | 122 | ||
120 | 123 | ||
121 | class TestFileBasedBuilder(TestCase): | 124 | class TestFileBasedBuilder(TestCase): |
122 | |||
123 | class StubBuilder(cb.FileBasedClientBuilder): | 125 | class StubBuilder(cb.FileBasedClientBuilder): |
124 | 126 | ||
125 | DEFAULT_CONFIG_FILE = "foo" | 127 | DEFAULT_CONFIG_FILE = "foo" |
@@ -170,7 +172,6 @@ class TestFileBasedBuilder(TestCase): | |||
170 | 172 | ||
171 | 173 | ||
172 | class TestPydoraConfigFileBuilder(TestCase): | 174 | class TestPydoraConfigFileBuilder(TestCase): |
173 | |||
174 | def test_cfg_to_dict(self): | 175 | def test_cfg_to_dict(self): |
175 | cfg = Mock() | 176 | cfg = Mock() |
176 | cfg.items = Mock(return_value=[("a", "b"), ("c", "d")]) | 177 | cfg.items = Mock(return_value=[("a", "b"), ("c", "d")]) |
@@ -184,38 +185,43 @@ class TestPydoraConfigFileBuilder(TestCase): | |||
184 | path = os.path.join(os.path.dirname(__file__), "pydora.cfg") | 185 | path = os.path.join(os.path.dirname(__file__), "pydora.cfg") |
185 | cfg = cb.PydoraConfigFileBuilder(path).parse_config() | 186 | cfg = cb.PydoraConfigFileBuilder(path).parse_config() |
186 | 187 | ||
187 | self.assertDictEqual(cfg, { | 188 | self.assertDictEqual( |
188 | "AUDIO_QUALITY": "test_quality", | 189 | cfg, |
189 | "DECRYPTION_KEY": "test_decryption_key", | 190 | { |
190 | "DEVICE": "test_device", | 191 | "AUDIO_QUALITY": "test_quality", |
191 | "ENCRYPTION_KEY": "test_encryption_key", | 192 | "DECRYPTION_KEY": "test_decryption_key", |
192 | "PARTNER_PASSWORD": "test_partner_password", | 193 | "DEVICE": "test_device", |
193 | "PARTNER_USER": "test_partner_username", | 194 | "ENCRYPTION_KEY": "test_encryption_key", |
194 | "API_HOST": "test_host", | 195 | "PARTNER_PASSWORD": "test_partner_password", |
195 | "USER": { | 196 | "PARTNER_USER": "test_partner_username", |
196 | "USERNAME": "test_username", | 197 | "API_HOST": "test_host", |
197 | "PASSWORD": "test_password", | 198 | "USER": { |
198 | } | 199 | "USERNAME": "test_username", |
199 | }) | 200 | "PASSWORD": "test_password", |
201 | }, | ||
202 | }, | ||
203 | ) | ||
200 | 204 | ||
201 | 205 | ||
202 | class TestPianobarConfigFileBuilder(TestCase): | 206 | class TestPianobarConfigFileBuilder(TestCase): |
203 | |||
204 | def test_integration(self): | 207 | def test_integration(self): |
205 | path = os.path.join(os.path.dirname(__file__), "pianobar.cfg") | 208 | path = os.path.join(os.path.dirname(__file__), "pianobar.cfg") |
206 | cfg = cb.PianobarConfigFileBuilder(path).parse_config() | 209 | cfg = cb.PianobarConfigFileBuilder(path).parse_config() |
207 | 210 | ||
208 | self.assertDictEqual(cfg, { | 211 | self.assertDictEqual( |
209 | "AUDIO_QUALITY": "test_qualityQuality", | 212 | cfg, |
210 | "DECRYPTION_KEY": "test_decryption_key", | 213 | { |
211 | "DEVICE": "test_device", | 214 | "AUDIO_QUALITY": "test_qualityQuality", |
212 | "ENCRYPTION_KEY": "test_encryption_key", | 215 | "DECRYPTION_KEY": "test_decryption_key", |
213 | "PARTNER_PASSWORD": "test_partner_password", | 216 | "DEVICE": "test_device", |
214 | "PARTNER_USER": "test_partner_username", | 217 | "ENCRYPTION_KEY": "test_encryption_key", |
215 | "API_HOST": "test_host/services/json/", | 218 | "PARTNER_PASSWORD": "test_partner_password", |
216 | "PROXY": "test_proxy", | 219 | "PARTNER_USER": "test_partner_username", |
217 | "USER": { | 220 | "API_HOST": "test_host/services/json/", |
218 | "USERNAME": "test_username", | 221 | "PROXY": "test_proxy", |
219 | "PASSWORD": "test_password", | 222 | "USER": { |
220 | } | 223 | "USERNAME": "test_username", |
221 | }) | 224 | "PASSWORD": "test_password", |
225 | }, | ||
226 | }, | ||
227 | ) | ||