Merge lp:~elachuni/piston-mini-client/304-is-valid-response-status into lp:piston-mini-client

Proposed by Anthony Lenton
Status: Merged
Merged at revision: 22
Proposed branch: lp:~elachuni/piston-mini-client/304-is-valid-response-status
Merge into: lp:piston-mini-client
Diff against target: 47 lines (+13/-2)
3 files modified
.bzrignore (+1/-1)
piston_mini_client/__init__.py (+1/-1)
piston_mini_client/test/test_resource.py (+11/-0)
To merge this branch: bzr merge lp:~elachuni/piston-mini-client/304-is-valid-response-status
Reviewer Review Type Date Requested Status
Michael Nelson Approve
Review via email: mp+44339@code.launchpad.net

Description of the change

This branch avoids 304 responses from the server being raised as APIErrors.
Also, a test was added for the full list of valid status codes.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :

Nice - isn't Mock great ;)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2010-11-17 01:33:04 +0000
3+++ .bzrignore 2010-12-21 13:51:12 +0000
4@@ -1,3 +1,3 @@
5 .coverage
6-cover
7+htmlcov
8 doc/_build
9
10=== modified file 'piston_mini_client/__init__.py'
11--- piston_mini_client/__init__.py 2010-12-09 21:02:11 +0000
12+++ piston_mini_client/__init__.py 2010-12-21 13:51:12 +0000
13@@ -178,7 +178,7 @@
14 raise APIError('Unable to connect to %s' % self._service_root)
15 else:
16 raise
17- if response['status'] not in ['200', '201']:
18+ if response['status'] not in ['200', '201', '304']:
19 raise APIError('%s: %s\n-----\n%s' % (response['status'],
20 response, body))
21 return response, body
22
23=== modified file 'piston_mini_client/test/test_resource.py'
24--- piston_mini_client/test/test_resource.py 2010-12-09 21:02:11 +0000
25+++ piston_mini_client/test/test_resource.py 2010-12-21 13:51:12 +0000
26@@ -1,3 +1,4 @@
27+from mock import patch
28 from unittest import TestCase
29 from wsgi_intercept import add_wsgi_intercept, remove_wsgi_intercept
30 from wsgi_intercept.httplib2_intercept import install, uninstall
31@@ -75,6 +76,16 @@
32 self.assertEqual('/stew', self.called['path'])
33 self.assertEqual('foo=bar', self.called['query'])
34
35+ @patch('httplib2.Http.request')
36+ def test_valid_status_codes_dont_raise_exception(self, mock_request):
37+ for status in ['200', '201', '304']:
38+ expected_response = {'status': status}
39+ expected_body = '"hello world!"'
40+ mock_request.return_value = (expected_response, expected_body)
41+ api = self.CoffeeAPI()
42+ response, body = api._get('/simmer')
43+ self.assertEqual(expected_response, response)
44+
45 def test_get_with_extra_args(self):
46 api = self.CoffeeAPI()
47 api._get('/stew?zot=ping', args={'foo': 'bar'})

Subscribers

People subscribed via source and target branches