Merge lp:~elachuni/piston-mini-client/fix-tests into lp:piston-mini-client
- fix-tests
- Merge into trunk
Proposed by
Anthony Lenton
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Anthony Lenton | ||||
Approved revision: | 66 | ||||
Merged at revision: | 61 | ||||
Proposed branch: | lp:~elachuni/piston-mini-client/fix-tests | ||||
Merge into: | lp:piston-mini-client | ||||
Diff against target: |
672 lines (+123/-102) 13 files modified
piston_mini_client/__init__.py (+25/-24) piston_mini_client/auth.py (+3/-2) piston_mini_client/failhandlers.py (+2/-2) piston_mini_client/tests/test_auth.py (+5/-0) piston_mini_client/tests/test_disable_ssl_check.py (+3/-3) piston_mini_client/tests/test_failhandlers.py (+4/-4) piston_mini_client/tests/test_log_to_file.py (+3/-3) piston_mini_client/tests/test_pep8.py (+21/-28) piston_mini_client/tests/test_resource.py (+39/-26) piston_mini_client/tests/test_serializers.py (+1/-1) piston_mini_client/tests/test_timeout.py (+4/-4) piston_mini_client/tests/test_validators.py (+8/-2) piston_mini_client/validators.py (+5/-3) |
||||
To merge this branch: | bzr merge lp:~elachuni/piston-mini-client/fix-tests | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jonathan Lange (community) | Approve | ||
software-store-developers | Pending | ||
Review via email: mp+117306@code.launchpad.net |
Commit message
Made tests pass with the latest pep8 release.
Description of the change
This branch fixes the tests that were failing in trunk:
- The latest pep8 release changes the internal layout of the module, so the test that uses it needed to apply matching changes.
- oauth is still broken on Python 3 (it attempts to import urlparse, for starters), so the OAuth test is skipped on Python 3.
To post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'piston_mini_client/__init__.py' | |||
2 | --- piston_mini_client/__init__.py 2012-07-30 15:59:14 +0000 | |||
3 | +++ piston_mini_client/__init__.py 2012-07-30 17:16:48 +0000 | |||
4 | @@ -212,8 +212,8 @@ | |||
5 | 212 | data = {} | 212 | data = {} |
6 | 213 | for att in self._atts: | 213 | for att in self._atts: |
7 | 214 | if not hasattr(self, att): | 214 | if not hasattr(self, att): |
10 | 215 | raise ValueError("Attempted to serialize attribute '%s'" | 215 | raise ValueError( |
11 | 216 | % att) | 216 | "Attempted to serialize attribute '%s'" % att) |
12 | 217 | data[att] = getattr(self, att) | 217 | data[att] = getattr(self, att) |
13 | 218 | return data | 218 | return data |
14 | 219 | 219 | ||
15 | @@ -333,8 +333,8 @@ | |||
16 | 333 | def _get_http_obj_for_scheme(self, scheme): | 333 | def _get_http_obj_for_scheme(self, scheme): |
17 | 334 | proxy_info = self._get_proxy_info(scheme) | 334 | proxy_info = self._get_proxy_info(scheme) |
18 | 335 | http = None | 335 | http = None |
21 | 336 | if (self._disable_ssl_validation or | 336 | check_disabled_in_env = os.environ.get(DISABLE_SSL_VALIDATION_ENVVAR) |
22 | 337 | os.environ.get(DISABLE_SSL_VALIDATION_ENVVAR)): | 337 | if self._disable_ssl_validation or check_disabled_in_env: |
23 | 338 | try: | 338 | try: |
24 | 339 | http = httplib2.Http( | 339 | http = httplib2.Http( |
25 | 340 | cache=self._httplib2_cache, | 340 | cache=self._httplib2_cache, |
26 | @@ -346,7 +346,7 @@ | |||
27 | 346 | pass | 346 | pass |
28 | 347 | if http is None: | 347 | if http is None: |
29 | 348 | http = httplib2.Http(cache=self._httplib2_cache, | 348 | http = httplib2.Http(cache=self._httplib2_cache, |
31 | 349 | timeout=self._timeout, proxy_info=proxy_info) | 349 | timeout=self._timeout, proxy_info=proxy_info) |
32 | 350 | return http | 350 | return http |
33 | 351 | 351 | ||
34 | 352 | def _get_proxy_info(self, scheme): | 352 | def _get_proxy_info(self, scheme): |
35 | @@ -396,10 +396,10 @@ | |||
36 | 396 | path += urlencode(args) | 396 | path += urlencode(args) |
37 | 397 | headers = self._prepare_headers(extra_headers=extra_headers) | 397 | headers = self._prepare_headers(extra_headers=extra_headers) |
38 | 398 | return self._request(path, method='GET', scheme=scheme, | 398 | return self._request(path, method='GET', scheme=scheme, |
40 | 399 | headers=headers) | 399 | headers=headers) |
41 | 400 | 400 | ||
42 | 401 | def _post(self, path, data=None, content_type=None, scheme=None, | 401 | def _post(self, path, data=None, content_type=None, scheme=None, |
44 | 402 | extra_headers=None): | 402 | extra_headers=None): |
45 | 403 | """Perform an HTTP POST request. | 403 | """Perform an HTTP POST request. |
46 | 404 | 404 | ||
47 | 405 | The provided ``path`` is appended to this api's ``_service_root`` | 405 | The provided ``path`` is appended to this api's ``_service_root`` |
48 | @@ -424,12 +424,12 @@ | |||
49 | 424 | will be added to the http request. | 424 | will be added to the http request. |
50 | 425 | """ | 425 | """ |
51 | 426 | body, headers = self._prepare_request(data, content_type, | 426 | body, headers = self._prepare_request(data, content_type, |
53 | 427 | extra_headers=extra_headers) | 427 | extra_headers=extra_headers) |
54 | 428 | return self._request(path, method='POST', body=body, | 428 | return self._request(path, method='POST', body=body, |
56 | 429 | headers=headers, scheme=scheme) | 429 | headers=headers, scheme=scheme) |
57 | 430 | 430 | ||
58 | 431 | def _put(self, path, data=None, content_type=None, scheme=None, | 431 | def _put(self, path, data=None, content_type=None, scheme=None, |
60 | 432 | extra_headers=None): | 432 | extra_headers=None): |
61 | 433 | """Perform an HTTP PUT request. | 433 | """Perform an HTTP PUT request. |
62 | 434 | 434 | ||
63 | 435 | The provided ``path`` is appended to this api's ``_service_root`` | 435 | The provided ``path`` is appended to this api's ``_service_root`` |
64 | @@ -454,9 +454,9 @@ | |||
65 | 454 | will be added to the http request. | 454 | will be added to the http request. |
66 | 455 | """ | 455 | """ |
67 | 456 | body, headers = self._prepare_request(data, content_type, | 456 | body, headers = self._prepare_request(data, content_type, |
69 | 457 | extra_headers=extra_headers) | 457 | extra_headers=extra_headers) |
70 | 458 | return self._request(path, method='PUT', body=body, | 458 | return self._request(path, method='PUT', body=body, |
72 | 459 | headers=headers, scheme=scheme) | 459 | headers=headers, scheme=scheme) |
73 | 460 | 460 | ||
74 | 461 | def _delete(self, path, scheme=None, extra_headers=None): | 461 | def _delete(self, path, scheme=None, extra_headers=None): |
75 | 462 | """Perform an HTTP DELETE request. | 462 | """Perform an HTTP DELETE request. |
76 | @@ -473,10 +473,10 @@ | |||
77 | 473 | """ | 473 | """ |
78 | 474 | headers = self._prepare_headers(extra_headers=extra_headers) | 474 | headers = self._prepare_headers(extra_headers=extra_headers) |
79 | 475 | return self._request(path, method='DELETE', scheme=scheme, | 475 | return self._request(path, method='DELETE', scheme=scheme, |
81 | 476 | headers=headers) | 476 | headers=headers) |
82 | 477 | 477 | ||
83 | 478 | def _prepare_request(self, data=None, content_type=None, | 478 | def _prepare_request(self, data=None, content_type=None, |
85 | 479 | extra_headers=None): | 479 | extra_headers=None): |
86 | 480 | """Put together a set of headers and a body for a request. | 480 | """Put together a set of headers and a body for a request. |
87 | 481 | 481 | ||
88 | 482 | If ``content_type`` is not provided, ``self.default_content_type`` | 482 | If ``content_type`` is not provided, ``self.default_content_type`` |
89 | @@ -550,8 +550,8 @@ | |||
90 | 550 | if self.log_filename: | 550 | if self.log_filename: |
91 | 551 | self._dump_request(url, method, body, headers) | 551 | self._dump_request(url, method, body, headers) |
92 | 552 | try: | 552 | try: |
95 | 553 | response, response_body = self._http[scheme].request(url, | 553 | response, response_body = self._http[scheme].request( |
96 | 554 | method=method, body=body, headers=headers) | 554 | url, method=method, body=body, headers=headers) |
97 | 555 | except AttributeError as e: | 555 | except AttributeError as e: |
98 | 556 | # Special case out httplib2's way of telling us unable to connect | 556 | # Special case out httplib2's way of telling us unable to connect |
99 | 557 | if e.args[0] == "'NoneType' object has no attribute 'makefile'": | 557 | if e.args[0] == "'NoneType' object has no attribute 'makefile'": |
100 | @@ -560,10 +560,10 @@ | |||
101 | 560 | raise | 560 | raise |
102 | 561 | except socket.timeout as e: | 561 | except socket.timeout as e: |
103 | 562 | raise TimeoutError('Timed out attempting to connect to %s' % | 562 | raise TimeoutError('Timed out attempting to connect to %s' % |
105 | 563 | self._service_root) | 563 | self._service_root) |
106 | 564 | except (socket.gaierror, socket.error) as e: | 564 | except (socket.gaierror, socket.error) as e: |
109 | 565 | raise SocketError('connecting to %s: %s' % (self._service_root, | 565 | msg = 'connecting to %s: %s' % (self._service_root, e.message) |
110 | 566 | e.message)) | 566 | raise SocketError(msg) |
111 | 567 | if self.log_filename: | 567 | if self.log_filename: |
112 | 568 | self._dump_response(response, response_body) | 568 | self._dump_response(response, response_body) |
113 | 569 | handler = self.fail_handler(url, method, body, headers) | 569 | handler = self.fail_handler(url, method, body, headers) |
114 | @@ -573,16 +573,16 @@ | |||
115 | 573 | def _dump_request(self, url, method, body, headers): | 573 | def _dump_request(self, url, method, body, headers): |
116 | 574 | try: | 574 | try: |
117 | 575 | with open(self.log_filename, 'a') as f: | 575 | with open(self.log_filename, 'a') as f: |
120 | 576 | f.write("{0}: {1}".format(datetime.now(), | 576 | formatted = format_request(url, method, body, headers) |
121 | 577 | format_request(url, method, body, headers))) | 577 | f.write("{0}: {1}".format(datetime.now(), formatted)) |
122 | 578 | except IOError: | 578 | except IOError: |
123 | 579 | pass | 579 | pass |
124 | 580 | 580 | ||
125 | 581 | def _dump_response(self, response, body): | 581 | def _dump_response(self, response, body): |
126 | 582 | try: | 582 | try: |
127 | 583 | with open(self.log_filename, 'a') as f: | 583 | with open(self.log_filename, 'a') as f: |
130 | 584 | f.write("{0}: {1}".format(datetime.now(), | 584 | formatted = format_response(response, body) |
131 | 585 | format_response(response, body))) | 585 | f.write("{0}: {1}".format(datetime.now(), formatted)) |
132 | 586 | except IOError: | 586 | except IOError: |
133 | 587 | pass | 587 | pass |
134 | 588 | 588 | ||
135 | @@ -595,7 +595,8 @@ | |||
136 | 595 | cached_value = self._http[scheme].cache.get( | 595 | cached_value = self._http[scheme].cache.get( |
137 | 596 | httplib2.urlnorm(url)[-1]) | 596 | httplib2.urlnorm(url)[-1]) |
138 | 597 | if cached_value: | 597 | if cached_value: |
140 | 598 | info, content = cached_value.decode("utf-8").split('\r\n\r\n', 1) | 598 | info, content = cached_value.decode("utf-8").split( |
141 | 599 | '\r\n\r\n', 1) | ||
142 | 599 | return content | 600 | return content |
143 | 600 | 601 | ||
144 | 601 | def _path2url(self, path, scheme=None): | 602 | def _path2url(self, path, scheme=None): |
145 | 602 | 603 | ||
146 | === modified file 'piston_mini_client/auth.py' | |||
147 | --- piston_mini_client/auth.py 2012-06-14 08:19:19 +0000 | |||
148 | +++ piston_mini_client/auth.py 2012-07-30 17:16:48 +0000 | |||
149 | @@ -12,6 +12,7 @@ | |||
150 | 12 | 12 | ||
151 | 13 | import base64 | 13 | import base64 |
152 | 14 | 14 | ||
153 | 15 | |||
154 | 15 | class OAuthAuthorizer(object): | 16 | class OAuthAuthorizer(object): |
155 | 16 | """Authenticate to OAuth protected APIs.""" | 17 | """Authenticate to OAuth protected APIs.""" |
156 | 17 | def __init__(self, token_key, token_secret, consumer_key, consumer_secret, | 18 | def __init__(self, token_key, token_secret, consumer_key, consumer_secret, |
157 | @@ -33,13 +34,13 @@ | |||
158 | 33 | # Import oauth here so that you don't need it if you're not going | 34 | # Import oauth here so that you don't need it if you're not going |
159 | 34 | # to use it. Plan B: move this out into a separate oauth module. | 35 | # to use it. Plan B: move this out into a separate oauth module. |
160 | 35 | from oauth.oauth import (OAuthRequest, OAuthConsumer, OAuthToken, | 36 | from oauth.oauth import (OAuthRequest, OAuthConsumer, OAuthToken, |
162 | 36 | OAuthSignatureMethod_PLAINTEXT) | 37 | OAuthSignatureMethod_PLAINTEXT) |
163 | 37 | consumer = OAuthConsumer(self.consumer_key, self.consumer_secret) | 38 | consumer = OAuthConsumer(self.consumer_key, self.consumer_secret) |
164 | 38 | token = OAuthToken(self.token_key, self.token_secret) | 39 | token = OAuthToken(self.token_key, self.token_secret) |
165 | 39 | oauth_request = OAuthRequest.from_consumer_and_token( | 40 | oauth_request = OAuthRequest.from_consumer_and_token( |
166 | 40 | consumer, token, http_url=url) | 41 | consumer, token, http_url=url) |
167 | 41 | oauth_request.sign_request(OAuthSignatureMethod_PLAINTEXT(), | 42 | oauth_request.sign_request(OAuthSignatureMethod_PLAINTEXT(), |
169 | 42 | consumer, token) | 43 | consumer, token) |
170 | 43 | headers.update(oauth_request.to_header(self.oauth_realm)) | 44 | headers.update(oauth_request.to_header(self.oauth_realm)) |
171 | 44 | 45 | ||
172 | 45 | 46 | ||
173 | 46 | 47 | ||
174 | === modified file 'piston_mini_client/failhandlers.py' | |||
175 | --- piston_mini_client/failhandlers.py 2012-07-19 15:38:19 +0000 | |||
176 | +++ piston_mini_client/failhandlers.py 2012-07-30 17:16:48 +0000 | |||
177 | @@ -113,7 +113,7 @@ | |||
178 | 113 | raise APIError('No status code in response') | 113 | raise APIError('No status code in response') |
179 | 114 | if self.was_error(response): | 114 | if self.was_error(response): |
180 | 115 | raise APIError('%s: %s' % (response['status'], response), body, | 115 | raise APIError('%s: %s' % (response['status'], response), body, |
182 | 116 | data=self.data) | 116 | data=self.data) |
183 | 117 | return body | 117 | return body |
184 | 118 | 118 | ||
185 | 119 | 119 | ||
186 | @@ -197,5 +197,5 @@ | |||
187 | 197 | status = response.get('status') | 197 | status = response.get('status') |
188 | 198 | exception_class = self.exceptions.get(status, APIError) | 198 | exception_class = self.exceptions.get(status, APIError) |
189 | 199 | raise exception_class('%s: %s' % (status, response), body, | 199 | raise exception_class('%s: %s' % (status, response), body, |
191 | 200 | data=self.data) | 200 | data=self.data) |
192 | 201 | return body | 201 | return body |
193 | 202 | 202 | ||
194 | === modified file 'piston_mini_client/tests/test_auth.py' | |||
195 | --- piston_mini_client/tests/test_auth.py 2012-06-14 08:19:19 +0000 | |||
196 | +++ piston_mini_client/tests/test_auth.py 2012-07-30 17:16:48 +0000 | |||
197 | @@ -2,6 +2,7 @@ | |||
198 | 2 | # Copyright 2010-2012 Canonical Ltd. This software is licensed under the | 2 | # Copyright 2010-2012 Canonical Ltd. This software is licensed under the |
199 | 3 | # GNU Lesser General Public License version 3 (see the file LICENSE). | 3 | # GNU Lesser General Public License version 3 (see the file LICENSE). |
200 | 4 | 4 | ||
201 | 5 | import sys | ||
202 | 5 | from piston_mini_client.auth import OAuthAuthorizer, BasicAuthorizer | 6 | from piston_mini_client.auth import OAuthAuthorizer, BasicAuthorizer |
203 | 6 | from unittest import TestCase | 7 | from unittest import TestCase |
204 | 7 | 8 | ||
205 | @@ -19,6 +20,10 @@ | |||
206 | 19 | 20 | ||
207 | 20 | class OAuthAuthorizerTestCase(TestCase): | 21 | class OAuthAuthorizerTestCase(TestCase): |
208 | 21 | def test_sign_request(self): | 22 | def test_sign_request(self): |
209 | 23 | if sys.version_info[0] == 3: | ||
210 | 24 | # Skip on Python 3 as oauth is still broken there. | ||
211 | 25 | # don't use skipIf as it's missing on python2.6 | ||
212 | 26 | return | ||
213 | 22 | auth = OAuthAuthorizer('tkey', 'tsecret', 'ckey', 'csecret') | 27 | auth = OAuthAuthorizer('tkey', 'tsecret', 'ckey', 'csecret') |
214 | 23 | url = 'http://example.com/api' | 28 | url = 'http://example.com/api' |
215 | 24 | headers = {} | 29 | headers = {} |
216 | 25 | 30 | ||
217 | === modified file 'piston_mini_client/tests/test_disable_ssl_check.py' | |||
218 | --- piston_mini_client/tests/test_disable_ssl_check.py 2012-03-30 17:17:49 +0000 | |||
219 | +++ piston_mini_client/tests/test_disable_ssl_check.py 2012-07-30 17:16:48 +0000 | |||
220 | @@ -35,14 +35,14 @@ | |||
221 | 35 | api = DentistAPI() | 35 | api = DentistAPI() |
222 | 36 | 36 | ||
223 | 37 | self.assertTrue('disable_ssl_certificate_validation' not in | 37 | self.assertTrue('disable_ssl_certificate_validation' not in |
225 | 38 | mock_http.call_args[1]) | 38 | mock_http.call_args[1]) |
226 | 39 | 39 | ||
227 | 40 | @patch('httplib2.Http') | 40 | @patch('httplib2.Http') |
228 | 41 | def test_disable_via_constructor(self, mock_http): | 41 | def test_disable_via_constructor(self, mock_http): |
229 | 42 | api = DentistAPI(disable_ssl_validation=True) | 42 | api = DentistAPI(disable_ssl_validation=True) |
230 | 43 | 43 | ||
231 | 44 | self.assertTrue('disable_ssl_certificate_validation' in | 44 | self.assertTrue('disable_ssl_certificate_validation' in |
233 | 45 | mock_http.call_args[1]) | 45 | mock_http.call_args[1]) |
234 | 46 | 46 | ||
235 | 47 | @patch('httplib2.Http') | 47 | @patch('httplib2.Http') |
236 | 48 | def test_disable_via_envvar(self, mock_http): | 48 | def test_disable_via_envvar(self, mock_http): |
237 | @@ -50,4 +50,4 @@ | |||
238 | 50 | api = DentistAPI() | 50 | api = DentistAPI() |
239 | 51 | 51 | ||
240 | 52 | self.assertTrue('disable_ssl_certificate_validation' in | 52 | self.assertTrue('disable_ssl_certificate_validation' in |
242 | 53 | mock_http.call_args[1]) | 53 | mock_http.call_args[1]) |
243 | 54 | 54 | ||
244 | === modified file 'piston_mini_client/tests/test_failhandlers.py' | |||
245 | --- piston_mini_client/tests/test_failhandlers.py 2012-07-19 15:56:33 +0000 | |||
246 | +++ piston_mini_client/tests/test_failhandlers.py 2012-07-30 17:16:48 +0000 | |||
247 | @@ -120,7 +120,7 @@ | |||
248 | 120 | handler = ExceptionFailHandler('/foo', 'GET', '', {}) | 120 | handler = ExceptionFailHandler('/foo', 'GET', '', {}) |
249 | 121 | for status in bad_status: | 121 | for status in bad_status: |
250 | 122 | self.assertRaises(APIError, handler.handle, | 122 | self.assertRaises(APIError, handler.handle, |
252 | 123 | {'status': status}, '') | 123 | {'status': status}, '') |
253 | 124 | 124 | ||
254 | 125 | 125 | ||
255 | 126 | class NoneFailHandlerTestCase(TestCase): | 126 | class NoneFailHandlerTestCase(TestCase): |
256 | @@ -253,7 +253,7 @@ | |||
257 | 253 | mock_request.return_value = {'status': '200'}, '{"foo": "bar"}' | 253 | mock_request.return_value = {'status': '200'}, '{"foo": "bar"}' |
258 | 254 | 254 | ||
259 | 255 | self.assertTrue(isinstance(self.api.get_plant(), | 255 | self.assertTrue(isinstance(self.api.get_plant(), |
261 | 256 | PistonResponseObject)) | 256 | PistonResponseObject)) |
262 | 257 | 257 | ||
263 | 258 | @patch('httplib2.Http.request') | 258 | @patch('httplib2.Http.request') |
264 | 259 | def test_interacts_well_with_returns_list_of(self, mock_request): | 259 | def test_interacts_well_with_returns_list_of(self, mock_request): |
265 | @@ -285,7 +285,7 @@ | |||
266 | 285 | handler = MultiExceptionFailHandler('/foo', 'GET', '', {}) | 285 | handler = MultiExceptionFailHandler('/foo', 'GET', '', {}) |
267 | 286 | for status, exception in bad_status.items(): | 286 | for status, exception in bad_status.items(): |
268 | 287 | self.assertRaises(exception, handler.handle, {'status': status}, | 287 | self.assertRaises(exception, handler.handle, {'status': status}, |
270 | 288 | '') | 288 | '') |
271 | 289 | 289 | ||
272 | 290 | @patch('httplib2.Http.request') | 290 | @patch('httplib2.Http.request') |
273 | 291 | def test_interacts_well_with_returns_json_on_fail(self, mock_request): | 291 | def test_interacts_well_with_returns_json_on_fail(self, mock_request): |
274 | @@ -324,7 +324,7 @@ | |||
275 | 324 | mock_request.return_value = {'status': '200'}, '{"foo": "bar"}' | 324 | mock_request.return_value = {'status': '200'}, '{"foo": "bar"}' |
276 | 325 | 325 | ||
277 | 326 | self.assertTrue(isinstance(self.api.get_plant(), | 326 | self.assertTrue(isinstance(self.api.get_plant(), |
279 | 327 | PistonResponseObject)) | 327 | PistonResponseObject)) |
280 | 328 | 328 | ||
281 | 329 | @patch('httplib2.Http.request') | 329 | @patch('httplib2.Http.request') |
282 | 330 | def test_interacts_well_with_returns_list_of(self, mock_request): | 330 | def test_interacts_well_with_returns_list_of(self, mock_request): |
283 | 331 | 331 | ||
284 | === modified file 'piston_mini_client/tests/test_log_to_file.py' | |||
285 | --- piston_mini_client/tests/test_log_to_file.py 2012-06-14 08:10:28 +0000 | |||
286 | +++ piston_mini_client/tests/test_log_to_file.py 2012-07-30 17:16:48 +0000 | |||
287 | @@ -19,14 +19,14 @@ | |||
288 | 19 | @returns_json | 19 | @returns_json |
289 | 20 | def poke(self, data=None): | 20 | def poke(self, data=None): |
290 | 21 | return self._post('/poke/', data=data, | 21 | return self._post('/poke/', data=data, |
292 | 22 | extra_headers={'location': 'ribs'}) | 22 | extra_headers={'location': 'ribs'}) |
293 | 23 | 23 | ||
294 | 24 | 24 | ||
295 | 25 | class LogToFileTestCase(TestCase): | 25 | class LogToFileTestCase(TestCase): |
296 | 26 | @patch('httplib2.Http.request') | 26 | @patch('httplib2.Http.request') |
297 | 27 | def test_requests_are_dumped_to_file(self, mock_request): | 27 | def test_requests_are_dumped_to_file(self, mock_request): |
298 | 28 | mock_request.return_value = ({'status': '201', 'x-foo': 'bar'}, | 28 | mock_request.return_value = ({'status': '201', 'x-foo': 'bar'}, |
300 | 29 | '"Go away!"') | 29 | '"Go away!"') |
301 | 30 | 30 | ||
302 | 31 | with NamedTemporaryFile() as fp: | 31 | with NamedTemporaryFile() as fp: |
303 | 32 | api = AnnoyAPI(log_filename=fp.name) | 32 | api = AnnoyAPI(log_filename=fp.name) |
304 | @@ -41,7 +41,7 @@ | |||
305 | 41 | self.assertTrue(lines[0].endswith( | 41 | self.assertTrue(lines[0].endswith( |
306 | 42 | 'Request: POST http://test.info/api/1.0/poke/')) | 42 | 'Request: POST http://test.info/api/1.0/poke/')) |
307 | 43 | self.assertEqual(['Content-type: application/json', | 43 | self.assertEqual(['Content-type: application/json', |
309 | 44 | 'location: ribs', '', '[1, 2, 3]'], lines[1:5]) | 44 | 'location: ribs', '', '[1, 2, 3]'], lines[1:5]) |
310 | 45 | self.assertTrue(lines[5].endswith('Response: 201')) | 45 | self.assertTrue(lines[5].endswith('Response: 201')) |
311 | 46 | self.assertEqual(['x-foo: bar', '', '"Go away!"', ''], lines[6:]) | 46 | self.assertEqual(['x-foo: bar', '', '"Go away!"', ''], lines[6:]) |
312 | 47 | 47 | ||
313 | 48 | 48 | ||
314 | === modified file 'piston_mini_client/tests/test_pep8.py' | |||
315 | --- piston_mini_client/tests/test_pep8.py 2012-03-30 17:17:49 +0000 | |||
316 | +++ piston_mini_client/tests/test_pep8.py 2012-07-30 17:16:48 +0000 | |||
317 | @@ -15,36 +15,29 @@ | |||
318 | 15 | packages = [piston_mini_client] | 15 | packages = [piston_mini_client] |
319 | 16 | exclude = ['socks.py'] # Leave 3rd party dep. alone. | 16 | exclude = ['socks.py'] # Leave 3rd party dep. alone. |
320 | 17 | 17 | ||
321 | 18 | def message(self, text): | ||
322 | 19 | self.errors.append(text) | ||
323 | 20 | |||
324 | 21 | def setUp(self): | ||
325 | 22 | self.errors = [] | ||
326 | 23 | |||
327 | 24 | class Options(object): | ||
328 | 25 | exclude = self.exclude | ||
329 | 26 | filename = ['*.py'] | ||
330 | 27 | testsuite = '' | ||
331 | 28 | doctest = '' | ||
332 | 29 | counters = defaultdict(int) | ||
333 | 30 | messages = {} | ||
334 | 31 | verbose = 0 | ||
335 | 32 | quiet = 0 | ||
336 | 33 | repeat = True | ||
337 | 34 | show_source = False | ||
338 | 35 | show_pep8 = False | ||
339 | 36 | select = [] | ||
340 | 37 | ignore = [] | ||
341 | 38 | max_line_length = 79 | ||
342 | 39 | pep8.options = Options() | ||
343 | 40 | pep8.message = self.message | ||
344 | 41 | Options.physical_checks = pep8.find_checks('physical_line') | ||
345 | 42 | Options.logical_checks = pep8.find_checks('logical_line') | ||
346 | 43 | |||
347 | 44 | def test_all_code(self): | 18 | def test_all_code(self): |
348 | 19 | pep8style = pep8.StyleGuide( | ||
349 | 20 | counters=defaultdict(int), | ||
350 | 21 | doctest='', | ||
351 | 22 | exclude=self.exclude, | ||
352 | 23 | filename=['*.py'], | ||
353 | 24 | ignore=[], | ||
354 | 25 | messages={}, | ||
355 | 26 | repeat=True, | ||
356 | 27 | select=[], | ||
357 | 28 | show_pep8=False, | ||
358 | 29 | show_source=False, | ||
359 | 30 | max_line_length=79, | ||
360 | 31 | quiet=0, | ||
361 | 32 | statistics=False, | ||
362 | 33 | testsuite='', | ||
363 | 34 | verbose=0, | ||
364 | 35 | ) | ||
365 | 36 | |||
366 | 45 | for package in self.packages: | 37 | for package in self.packages: |
369 | 46 | pep8.input_dir(os.path.dirname(package.__file__)) | 38 | pep8style.input_dir(os.path.dirname(package.__file__)) |
370 | 47 | self.assertEqual([], self.errors) | 39 | self.assertEqual(pep8style.options.report.total_errors, 0) |
371 | 40 | |||
372 | 48 | 41 | ||
373 | 49 | if __name__ == "__main__": | 42 | if __name__ == "__main__": |
374 | 50 | unittest.main() | 43 | unittest.main() |
375 | 51 | 44 | ||
376 | === modified file 'piston_mini_client/tests/test_resource.py' | |||
377 | --- piston_mini_client/tests/test_resource.py 2012-07-30 15:59:14 +0000 | |||
378 | +++ piston_mini_client/tests/test_resource.py 2012-07-30 17:16:48 +0000 | |||
379 | @@ -27,11 +27,11 @@ | |||
380 | 27 | 27 | ||
381 | 28 | @patch('httplib2.Http.request') | 28 | @patch('httplib2.Http.request') |
382 | 29 | def test_request(self, mock_request): | 29 | def test_request(self, mock_request): |
385 | 30 | mock_request.return_value = ({'status': '200' | 30 | mock_request.return_value = ({'status': '200'}, 'hello world!') |
384 | 31 | }, 'hello world!') | ||
386 | 32 | api = self.CoffeeAPI() | 31 | api = self.CoffeeAPI() |
387 | 33 | api._request('/foo', 'POST', body='foo=bar') | 32 | api._request('/foo', 'POST', body='foo=bar') |
389 | 34 | mock_request.assert_called_with('http://localhost:12345/foo', | 33 | mock_request.assert_called_with( |
390 | 34 | 'http://localhost:12345/foo', | ||
391 | 35 | body='foo=bar', headers={}, method='POST') | 35 | body='foo=bar', headers={}, method='POST') |
392 | 36 | 36 | ||
393 | 37 | @patch('httplib2.Http.request') | 37 | @patch('httplib2.Http.request') |
394 | @@ -68,7 +68,8 @@ | |||
395 | 68 | cache = httplib2.FileCache(tmpdir, safe=safename) | 68 | cache = httplib2.FileCache(tmpdir, safe=safename) |
396 | 69 | http = httplib2.Http(cache=cache) | 69 | http = httplib2.Http(cache=cache) |
397 | 70 | cachekey = self.CoffeeAPI.default_service_root + path | 70 | cachekey = self.CoffeeAPI.default_service_root + path |
399 | 71 | http.cache.set(cachekey.encode('utf-8'), | 71 | http.cache.set( |
400 | 72 | cachekey.encode('utf-8'), | ||
401 | 72 | "header\r\n\r\nmy_cached_body_from_long_path\n".encode('utf-8')) | 73 | "header\r\n\r\nmy_cached_body_from_long_path\n".encode('utf-8')) |
402 | 73 | # ensure that we trigger a error like when offline (no dns) | 74 | # ensure that we trigger a error like when offline (no dns) |
403 | 74 | mock_request.side_effect = httplib2.ServerNotFoundError("") | 75 | mock_request.side_effect = httplib2.ServerNotFoundError("") |
404 | @@ -83,11 +84,11 @@ | |||
405 | 83 | def test_auth_request(self, mock_request): | 84 | def test_auth_request(self, mock_request): |
406 | 84 | mock_request.return_value = ({'status': '200'}, '""') | 85 | mock_request.return_value = ({'status': '200'}, '""') |
407 | 85 | api = self.CoffeeAPI(auth=BasicAuthorizer(username='foo', | 86 | api = self.CoffeeAPI(auth=BasicAuthorizer(username='foo', |
409 | 86 | password='bar')) | 87 | password='bar')) |
410 | 87 | api._request('/fee', 'GET') | 88 | api._request('/fee', 'GET') |
411 | 88 | kwargs = mock_request.call_args[1] | 89 | kwargs = mock_request.call_args[1] |
412 | 89 | self.assertEqual(kwargs['headers']['Authorization'], | 90 | self.assertEqual(kwargs['headers']['Authorization'], |
414 | 90 | 'Basic Zm9vOmJhcg==') | 91 | 'Basic Zm9vOmJhcg==') |
415 | 91 | self.assertEqual(kwargs['method'], 'GET') | 92 | self.assertEqual(kwargs['method'], 'GET') |
416 | 92 | 93 | ||
417 | 93 | @patch('httplib2.Http.request') | 94 | @patch('httplib2.Http.request') |
418 | @@ -116,10 +117,10 @@ | |||
419 | 116 | mock_request.return_value = ({'status': '200'}, '""') | 117 | mock_request.return_value = ({'status': '200'}, '""') |
420 | 117 | api = self.CoffeeAPI() | 118 | api = self.CoffeeAPI() |
421 | 118 | api._post('/serve', data={'foo': 'bar'}, | 119 | api._post('/serve', data={'foo': 'bar'}, |
423 | 119 | content_type='application/x-www-form-urlencoded') | 120 | content_type='application/x-www-form-urlencoded') |
424 | 120 | kwargs = mock_request.call_args[1] | 121 | kwargs = mock_request.call_args[1] |
425 | 121 | self.assertEqual(kwargs['headers']['Content-type'], | 122 | self.assertEqual(kwargs['headers']['Content-type'], |
427 | 122 | 'application/x-www-form-urlencoded') | 123 | 'application/x-www-form-urlencoded') |
428 | 123 | self.assertEqual(kwargs['method'], 'POST') | 124 | self.assertEqual(kwargs['method'], 'POST') |
429 | 124 | 125 | ||
430 | 125 | @patch('httplib2.Http.request') | 126 | @patch('httplib2.Http.request') |
431 | @@ -150,7 +151,7 @@ | |||
432 | 150 | body = api._get('/simmer') | 151 | body = api._get('/simmer') |
433 | 151 | self.assertEqual(expected_body, body) | 152 | self.assertEqual(expected_body, body) |
434 | 152 | mock_request.assert_called_with('http://localhost:12345/simmer', | 153 | mock_request.assert_called_with('http://localhost:12345/simmer', |
436 | 153 | body='', headers={}, method='GET') | 154 | body='', headers={}, method='GET') |
437 | 154 | 155 | ||
438 | 155 | @patch('httplib2.Http.request') | 156 | @patch('httplib2.Http.request') |
439 | 156 | def test_get_with_extra_args(self, mock_request): | 157 | def test_get_with_extra_args(self, mock_request): |
440 | @@ -187,7 +188,7 @@ | |||
441 | 187 | api = self.CoffeeAPI() | 188 | api = self.CoffeeAPI() |
442 | 188 | api._request('/foo', 'GET', scheme='https') | 189 | api._request('/foo', 'GET', scheme='https') |
443 | 189 | mock_request.assert_called_with('https://localhost:12345/foo', | 190 | mock_request.assert_called_with('https://localhost:12345/foo', |
445 | 190 | body='', headers={}, method='GET') | 191 | body='', headers={}, method='GET') |
446 | 191 | 192 | ||
447 | 192 | @patch('httplib2.Http.request') | 193 | @patch('httplib2.Http.request') |
448 | 193 | def test_get_scheme_switch_to_https(self, mock_request): | 194 | def test_get_scheme_switch_to_https(self, mock_request): |
449 | @@ -195,14 +196,15 @@ | |||
450 | 195 | api = self.CoffeeAPI() | 196 | api = self.CoffeeAPI() |
451 | 196 | api._get('/foo', scheme='https') | 197 | api._get('/foo', scheme='https') |
452 | 197 | mock_request.assert_called_with('https://localhost:12345/foo', | 198 | mock_request.assert_called_with('https://localhost:12345/foo', |
454 | 198 | body='', headers={}, method='GET') | 199 | body='', headers={}, method='GET') |
455 | 199 | 200 | ||
456 | 200 | @patch('httplib2.Http.request') | 201 | @patch('httplib2.Http.request') |
457 | 201 | def test_post_scheme_switch_to_https(self, mock_request): | 202 | def test_post_scheme_switch_to_https(self, mock_request): |
458 | 202 | mock_request.return_value = ({'status': '200'}, '""') | 203 | mock_request.return_value = ({'status': '200'}, '""') |
459 | 203 | api = self.CoffeeAPI() | 204 | api = self.CoffeeAPI() |
460 | 204 | api._post('/foo', scheme='https') | 205 | api._post('/foo', scheme='https') |
462 | 205 | mock_request.assert_called_with('https://localhost:12345/foo', | 206 | mock_request.assert_called_with( |
463 | 207 | 'https://localhost:12345/foo', | ||
464 | 206 | body='null', headers={'Content-type': 'application/json'}, | 208 | body='null', headers={'Content-type': 'application/json'}, |
465 | 207 | method='POST') | 209 | method='POST') |
466 | 208 | 210 | ||
467 | @@ -250,7 +252,8 @@ | |||
468 | 250 | mock_request.return_value = ({'status': '200'}, '""') | 252 | mock_request.return_value = ({'status': '200'}, '""') |
469 | 251 | api = self.CoffeeAPI() | 253 | api = self.CoffeeAPI() |
470 | 252 | api._put('/foo', scheme='https') | 254 | api._put('/foo', scheme='https') |
472 | 253 | mock_request.assert_called_with('https://localhost:12345/foo', | 255 | mock_request.assert_called_with( |
473 | 256 | 'https://localhost:12345/foo', | ||
474 | 254 | body='null', headers={'Content-type': 'application/json'}, | 257 | body='null', headers={'Content-type': 'application/json'}, |
475 | 255 | method='PUT') | 258 | method='PUT') |
476 | 256 | 259 | ||
477 | @@ -259,11 +262,11 @@ | |||
478 | 259 | mock_request.return_value = ({'status': '200'}, '""') | 262 | mock_request.return_value = ({'status': '200'}, '""') |
479 | 260 | api = self.CoffeeAPI() | 263 | api = self.CoffeeAPI() |
480 | 261 | api._put('/serve', data={'foo': 'bar'}, | 264 | api._put('/serve', data={'foo': 'bar'}, |
482 | 262 | content_type='application/x-www-form-urlencoded') | 265 | content_type='application/x-www-form-urlencoded') |
483 | 263 | kwargs = mock_request.call_args[1] | 266 | kwargs = mock_request.call_args[1] |
484 | 264 | self.assertEqual(kwargs['body'], 'foo=bar') | 267 | self.assertEqual(kwargs['body'], 'foo=bar') |
485 | 265 | self.assertEqual(kwargs['headers']['Content-type'], | 268 | self.assertEqual(kwargs['headers']['Content-type'], |
487 | 266 | 'application/x-www-form-urlencoded') | 269 | 'application/x-www-form-urlencoded') |
488 | 267 | self.assertEqual(kwargs['method'], 'PUT') | 270 | self.assertEqual(kwargs['method'], 'PUT') |
489 | 268 | 271 | ||
490 | 269 | @patch('httplib2.Http.request') | 272 | @patch('httplib2.Http.request') |
491 | @@ -273,17 +276,21 @@ | |||
492 | 273 | api.extra_headers = {'X-Foo': 'bar'} | 276 | api.extra_headers = {'X-Foo': 'bar'} |
493 | 274 | api._get('/foo') | 277 | api._get('/foo') |
494 | 275 | expected_headers = {'X-Foo': 'bar'} | 278 | expected_headers = {'X-Foo': 'bar'} |
496 | 276 | mock_request.assert_called_with('http://localhost:12345/foo', | 279 | mock_request.assert_called_with( |
497 | 280 | 'http://localhost:12345/foo', | ||
498 | 277 | body='', headers=expected_headers, method='GET') | 281 | body='', headers=expected_headers, method='GET') |
499 | 278 | api._delete('/foo') | 282 | api._delete('/foo') |
501 | 279 | mock_request.assert_called_with('http://localhost:12345/foo', | 283 | mock_request.assert_called_with( |
502 | 284 | 'http://localhost:12345/foo', | ||
503 | 280 | body='', headers=expected_headers, method='DELETE') | 285 | body='', headers=expected_headers, method='DELETE') |
504 | 281 | expected_headers['Content-type'] = 'application/json' | 286 | expected_headers['Content-type'] = 'application/json' |
505 | 282 | api._post('/foo') | 287 | api._post('/foo') |
507 | 283 | mock_request.assert_called_with('http://localhost:12345/foo', | 288 | mock_request.assert_called_with( |
508 | 289 | 'http://localhost:12345/foo', | ||
509 | 284 | body='null', headers=expected_headers, method='POST') | 290 | body='null', headers=expected_headers, method='POST') |
510 | 285 | api._put('/foo') | 291 | api._put('/foo') |
512 | 286 | mock_request.assert_called_with('http://localhost:12345/foo', | 292 | mock_request.assert_called_with( |
513 | 293 | 'http://localhost:12345/foo', | ||
514 | 287 | body='null', headers=expected_headers, method='PUT') | 294 | body='null', headers=expected_headers, method='PUT') |
515 | 288 | 295 | ||
516 | 289 | @patch('httplib2.Http.request') | 296 | @patch('httplib2.Http.request') |
517 | @@ -292,17 +299,21 @@ | |||
518 | 292 | api = self.CoffeeAPI() | 299 | api = self.CoffeeAPI() |
519 | 293 | api._get('/foo', extra_headers={'X-Foo': 'bar'}) | 300 | api._get('/foo', extra_headers={'X-Foo': 'bar'}) |
520 | 294 | expected_headers = {'X-Foo': 'bar'} | 301 | expected_headers = {'X-Foo': 'bar'} |
522 | 295 | mock_request.assert_called_with('http://localhost:12345/foo', | 302 | mock_request.assert_called_with( |
523 | 303 | 'http://localhost:12345/foo', | ||
524 | 296 | body='', headers=expected_headers, method='GET') | 304 | body='', headers=expected_headers, method='GET') |
525 | 297 | api._delete('/foo', extra_headers={'X-Foo': 'bar'}) | 305 | api._delete('/foo', extra_headers={'X-Foo': 'bar'}) |
527 | 298 | mock_request.assert_called_with('http://localhost:12345/foo', | 306 | mock_request.assert_called_with( |
528 | 307 | 'http://localhost:12345/foo', | ||
529 | 299 | body='', headers=expected_headers, method='DELETE') | 308 | body='', headers=expected_headers, method='DELETE') |
530 | 300 | expected_headers['Content-type'] = 'application/json' | 309 | expected_headers['Content-type'] = 'application/json' |
531 | 301 | api._post('/foo', extra_headers={'X-Foo': 'bar'}) | 310 | api._post('/foo', extra_headers={'X-Foo': 'bar'}) |
533 | 302 | mock_request.assert_called_with('http://localhost:12345/foo', | 311 | mock_request.assert_called_with( |
534 | 312 | 'http://localhost:12345/foo', | ||
535 | 303 | body='null', headers=expected_headers, method='POST') | 313 | body='null', headers=expected_headers, method='POST') |
536 | 304 | api._put('/foo', extra_headers={'X-Foo': 'bar'}) | 314 | api._put('/foo', extra_headers={'X-Foo': 'bar'}) |
538 | 305 | mock_request.assert_called_with('http://localhost:12345/foo', | 315 | mock_request.assert_called_with( |
539 | 316 | 'http://localhost:12345/foo', | ||
540 | 306 | body='null', headers=expected_headers, method='PUT') | 317 | body='null', headers=expected_headers, method='PUT') |
541 | 307 | 318 | ||
542 | 308 | @patch('httplib2.Http.request') | 319 | @patch('httplib2.Http.request') |
543 | @@ -317,12 +328,14 @@ | |||
544 | 317 | api = self.CoffeeAPI() | 328 | api = self.CoffeeAPI() |
545 | 318 | api.serializers = {'application/json': MySerializer()} | 329 | api.serializers = {'application/json': MySerializer()} |
546 | 319 | api._post('/foo', data=[]) | 330 | api._post('/foo', data=[]) |
548 | 320 | mock_request.assert_called_with('http://localhost:12345/foo', | 331 | mock_request.assert_called_with( |
549 | 332 | 'http://localhost:12345/foo', | ||
550 | 321 | body=expected, headers={'Content-type': 'application/json'}, | 333 | body=expected, headers={'Content-type': 'application/json'}, |
551 | 322 | method='POST') | 334 | method='POST') |
552 | 323 | 335 | ||
553 | 324 | api._put('/foo', data=None) | 336 | api._put('/foo', data=None) |
555 | 325 | mock_request.assert_called_with('http://localhost:12345/foo', | 337 | mock_request.assert_called_with( |
556 | 338 | 'http://localhost:12345/foo', | ||
557 | 326 | body=expected, headers={'Content-type': 'application/json'}, | 339 | body=expected, headers={'Content-type': 'application/json'}, |
558 | 327 | method='PUT') | 340 | method='PUT') |
559 | 328 | 341 | ||
560 | @@ -341,7 +354,7 @@ | |||
561 | 341 | api = self.CoffeeAPI() | 354 | api = self.CoffeeAPI() |
562 | 342 | api._delete('/sugar/12', scheme='https') | 355 | api._delete('/sugar/12', scheme='https') |
563 | 343 | mock_request.assert_called_with('https://localhost:12345/sugar/12', | 356 | mock_request.assert_called_with('https://localhost:12345/sugar/12', |
565 | 344 | body='', headers={}, method='DELETE') | 357 | body='', headers={}, method='DELETE') |
566 | 345 | 358 | ||
567 | 346 | def test_cachedir_crash_race_lp803280(self): | 359 | def test_cachedir_crash_race_lp803280(self): |
568 | 347 | def _simulate_race(path): | 360 | def _simulate_race(path): |
569 | 348 | 361 | ||
570 | === modified file 'piston_mini_client/tests/test_serializers.py' | |||
571 | --- piston_mini_client/tests/test_serializers.py 2012-03-30 17:17:49 +0000 | |||
572 | +++ piston_mini_client/tests/test_serializers.py 2012-07-30 17:16:48 +0000 | |||
573 | @@ -44,4 +44,4 @@ | |||
574 | 44 | # Maybe we should flatly refuse to serialize nested structures? | 44 | # Maybe we should flatly refuse to serialize nested structures? |
575 | 45 | serializer = FormSerializer() | 45 | serializer = FormSerializer() |
576 | 46 | self.assertEqual('foo=%7B%27a%27%3A+%27b%27%7D', | 46 | self.assertEqual('foo=%7B%27a%27%3A+%27b%27%7D', |
578 | 47 | serializer.serialize({'foo': {'a': 'b'}})) | 47 | serializer.serialize({'foo': {'a': 'b'}})) |
579 | 48 | 48 | ||
580 | === modified file 'piston_mini_client/tests/test_timeout.py' | |||
581 | --- piston_mini_client/tests/test_timeout.py 2012-04-02 14:23:33 +0000 | |||
582 | +++ piston_mini_client/tests/test_timeout.py 2012-07-30 17:16:48 +0000 | |||
583 | @@ -25,7 +25,7 @@ | |||
584 | 25 | api = LazyAPI(timeout=1) | 25 | api = LazyAPI(timeout=1) |
585 | 26 | self.assertEqual(1, api._timeout) | 26 | self.assertEqual(1, api._timeout) |
586 | 27 | mock_http.assert_called_with(cache=None, proxy_info=None, timeout=1, | 27 | mock_http.assert_called_with(cache=None, proxy_info=None, timeout=1, |
588 | 28 | disable_ssl_certificate_validation=True) | 28 | disable_ssl_certificate_validation=True) |
589 | 29 | 29 | ||
590 | 30 | @patch('os.environ.get') | 30 | @patch('os.environ.get') |
591 | 31 | @patch('httplib2.Http') | 31 | @patch('httplib2.Http') |
592 | @@ -34,7 +34,7 @@ | |||
593 | 34 | api = LazyAPI() | 34 | api = LazyAPI() |
594 | 35 | self.assertEqual(3.14, api._timeout) | 35 | self.assertEqual(3.14, api._timeout) |
595 | 36 | mock_http.assert_called_with(cache=None, proxy_info=None, timeout=3.14, | 36 | mock_http.assert_called_with(cache=None, proxy_info=None, timeout=3.14, |
597 | 37 | disable_ssl_certificate_validation=True) | 37 | disable_ssl_certificate_validation=True) |
598 | 38 | 38 | ||
599 | 39 | @patch('os.environ.get') | 39 | @patch('os.environ.get') |
600 | 40 | @patch('httplib2.Http') | 40 | @patch('httplib2.Http') |
601 | @@ -47,7 +47,7 @@ | |||
602 | 47 | @patch('os.environ.get') | 47 | @patch('os.environ.get') |
603 | 48 | @patch('httplib2.Http') | 48 | @patch('httplib2.Http') |
604 | 49 | def test_no_nothing_falls_back_to_system_default(self, mock_http, | 49 | def test_no_nothing_falls_back_to_system_default(self, mock_http, |
606 | 50 | mock_get): | 50 | mock_get): |
607 | 51 | class DefaultAPI(PistonAPI): | 51 | class DefaultAPI(PistonAPI): |
608 | 52 | default_service_root = 'http://test.info/api/1.0/' | 52 | default_service_root = 'http://test.info/api/1.0/' |
609 | 53 | 53 | ||
610 | @@ -63,7 +63,7 @@ | |||
611 | 63 | api = LazyAPI() | 63 | api = LazyAPI() |
612 | 64 | self.assertEqual(42, api._timeout) | 64 | self.assertEqual(42, api._timeout) |
613 | 65 | mock_http.assert_called_with(cache=None, proxy_info=None, timeout=42, | 65 | mock_http.assert_called_with(cache=None, proxy_info=None, timeout=42, |
615 | 66 | disable_ssl_certificate_validation=True) | 66 | disable_ssl_certificate_validation=True) |
616 | 67 | 67 | ||
617 | 68 | @patch('httplib2.HTTPConnectionWithTimeout.connect') | 68 | @patch('httplib2.HTTPConnectionWithTimeout.connect') |
618 | 69 | def test_timeout_is_handled_by_failhandler(self, mock_connect): | 69 | def test_timeout_is_handled_by_failhandler(self, mock_connect): |
619 | 70 | 70 | ||
620 | === modified file 'piston_mini_client/tests/test_validators.py' | |||
621 | --- piston_mini_client/tests/test_validators.py 2012-03-30 17:17:49 +0000 | |||
622 | +++ piston_mini_client/tests/test_validators.py 2012-07-30 17:16:48 +0000 | |||
623 | @@ -2,8 +2,14 @@ | |||
624 | 2 | # Copyright 2010-2012 Canonical Ltd. This software is licensed under the | 2 | # Copyright 2010-2012 Canonical Ltd. This software is licensed under the |
625 | 3 | # GNU Lesser General Public License version 3 (see the file LICENSE). | 3 | # GNU Lesser General Public License version 3 (see the file LICENSE). |
626 | 4 | 4 | ||
629 | 5 | from piston_mini_client.validators import (validate_pattern, validate, | 5 | from piston_mini_client.validators import ( |
630 | 6 | validate_integer, oauth_protected, basic_protected, ValidationException) | 6 | basic_protected, |
631 | 7 | oauth_protected, | ||
632 | 8 | validate, | ||
633 | 9 | validate_integer, | ||
634 | 10 | validate_pattern, | ||
635 | 11 | ValidationException, | ||
636 | 12 | ) | ||
637 | 7 | from piston_mini_client.auth import OAuthAuthorizer, BasicAuthorizer | 13 | from piston_mini_client.auth import OAuthAuthorizer, BasicAuthorizer |
638 | 8 | from unittest import TestCase | 14 | from unittest import TestCase |
639 | 9 | 15 | ||
640 | 10 | 16 | ||
641 | === modified file 'piston_mini_client/validators.py' | |||
642 | --- piston_mini_client/validators.py 2012-06-13 13:25:54 +0000 | |||
643 | +++ piston_mini_client/validators.py 2012-07-30 17:16:48 +0000 | |||
644 | @@ -42,7 +42,7 @@ | |||
645 | 42 | if not re.match(pattern, kwargs[varname]): | 42 | if not re.match(pattern, kwargs[varname]): |
646 | 43 | raise ValidationException( | 43 | raise ValidationException( |
647 | 44 | "Argument '%s' must match pattern '%s'" % (varname, | 44 | "Argument '%s' must match pattern '%s'" % (varname, |
649 | 45 | pattern)) | 45 | pattern)) |
650 | 46 | elif required: | 46 | elif required: |
651 | 47 | raise ValidationException( | 47 | raise ValidationException( |
652 | 48 | "Required named argument '%s' missing" % varname) | 48 | "Required named argument '%s' missing" % varname) |
653 | @@ -111,7 +111,8 @@ | |||
654 | 111 | @wraps(func) | 111 | @wraps(func) |
655 | 112 | def wrapper(self, *args, **kwargs): | 112 | def wrapper(self, *args, **kwargs): |
656 | 113 | if not hasattr(self, '_auth') or self._auth is None: | 113 | if not hasattr(self, '_auth') or self._auth is None: |
658 | 114 | raise ValidationException("This method is OAuth protected. " | 114 | raise ValidationException( |
659 | 115 | "This method is OAuth protected. " | ||
660 | 115 | "Pass in an 'auth' argument to the constructor.") | 116 | "Pass in an 'auth' argument to the constructor.") |
661 | 116 | if not isinstance(self._auth, OAuthAuthorizer): | 117 | if not isinstance(self._auth, OAuthAuthorizer): |
662 | 117 | raise ValidationException("self.auth must be an OAuthAuthorizer.") | 118 | raise ValidationException("self.auth must be an OAuthAuthorizer.") |
663 | @@ -128,7 +129,8 @@ | |||
664 | 128 | @wraps(func) | 129 | @wraps(func) |
665 | 129 | def wrapper(self, *args, **kwargs): | 130 | def wrapper(self, *args, **kwargs): |
666 | 130 | if not hasattr(self, '_auth') or self._auth is None: | 131 | if not hasattr(self, '_auth') or self._auth is None: |
668 | 131 | raise ValidationException("This method uses Basic auth. " | 132 | raise ValidationException( |
669 | 133 | "This method uses Basic auth. " | ||
670 | 132 | "Pass in an 'auth' argument to the constructor.") | 134 | "Pass in an 'auth' argument to the constructor.") |
671 | 133 | if not isinstance(self._auth, BasicAuthorizer): | 135 | if not isinstance(self._auth, BasicAuthorizer): |
672 | 134 | raise ValidationException("self.auth must be a BasicAuthorizer.") | 136 | raise ValidationException("self.auth must be a BasicAuthorizer.") |
Looks good to me. Thanks.