Merge lp:~elachuni/piston-mini-client/debug-envvar into lp:piston-mini-client

Proposed by Anthony Lenton
Status: Merged
Merged at revision: 30
Proposed branch: lp:~elachuni/piston-mini-client/debug-envvar
Merge into: lp:piston-mini-client
Diff against target: 87 lines (+37/-1)
4 files modified
doc/envvars.rst (+6/-0)
doc/index.rst (+2/-1)
piston_mini_client/failhandlers.py (+5/-0)
piston_mini_client/tests/test_failhandlers.py (+24/-0)
To merge this branch: bzr merge lp:~elachuni/piston-mini-client/debug-envvar
Reviewer Review Type Date Requested Status
Ricardo Kirkner Approve
Review via email: mp+54365@code.launchpad.net

Description of the change

Overview
========
This branch makes APIErrors aware of the PISTON_MINI_CLIENT_DEBUG environment variable.

Details
=======
If set, APIErrors will print out the full server response by default, to make debugging easier.
Brief docs and tests were also added.

To post a comment you must log in.
31. By Anthony Lenton

Small doc fix and added a test.

Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

Very nice work, including the documentation for the change.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'doc/envvars.rst'
--- doc/envvars.rst 1970-01-01 00:00:00 +0000
+++ doc/envvars.rst 2011-03-22 16:32:10 +0000
@@ -0,0 +1,6 @@
1Environment variables
2=====================
3
4These environment variables affect the behaviour of ``piston_mini_client``:
5 * ``PISTON_MINI_CLIENT_DEBUG``: If set, all ``APIError`` exceptions will
6 report the full response from the server when printed, not only the headers.
07
=== modified file 'doc/index.rst'
--- doc/index.rst 2011-01-20 03:39:17 +0000
+++ doc/index.rst 2011-03-22 16:32:10 +0000
@@ -4,7 +4,7 @@
4 contain the root `toctree` directive.4 contain the root `toctree` directive.
55
6Welcome to piston_mini_client's documentation!6Welcome to piston_mini_client's documentation!
7========================================7==============================================
88
9Contents:9Contents:
1010
@@ -13,6 +13,7 @@
1313
14 quickstart14 quickstart
15 reference15 reference
16 envvars
1617
17Overview18Overview
18========19========
1920
=== modified file 'piston_mini_client/failhandlers.py'
--- piston_mini_client/failhandlers.py 2011-01-20 04:56:36 +0000
+++ piston_mini_client/failhandlers.py 2011-03-22 16:32:10 +0000
@@ -17,11 +17,16 @@
17 'MultiExceptionFailHandler',17 'MultiExceptionFailHandler',
18]18]
1919
20import os
21
20class APIError(Exception):22class APIError(Exception):
21 def __init__(self, msg, body=None):23 def __init__(self, msg, body=None):
22 self.msg = msg24 self.msg = msg
23 self.body = body25 self.body = body
26 self.debug = os.environ.get('PISTON_MINI_CLIENT_DEBUG', False)
24 def __str__(self):27 def __str__(self):
28 if self.debug:
29 return "%s\nReceived body:\n%s" % (self.msg, self.body)
25 return self.msg30 return self.msg
2631
2732
2833
=== modified file 'piston_mini_client/tests/test_failhandlers.py'
--- piston_mini_client/tests/test_failhandlers.py 2011-01-12 17:21:36 +0000
+++ piston_mini_client/tests/test_failhandlers.py 2011-03-22 16:32:10 +0000
@@ -41,6 +41,30 @@
41 return self._get('/plant')41 return self._get('/plant')
4242
4343
44class APIErrorTestCase(TestCase):
45 def test_default_repr(self):
46 """Check that usually only msg is printed out"""
47 err = APIError(msg='foo', body='bar')
48 err.debug = False
49 self.assertEqual('foo', str(err))
50
51 def test_verbose_repr(self):
52 """Check that body is also included if in verbose mode"""
53 err = APIError(msg='foo', body='bar')
54 err.debug = True
55 self.assertTrue('bar' in str(err))
56
57 @patch('os.environ.get')
58 def test_debug_gets_set_from_environment(self, mock_get):
59 """Check that debug is initialized from the environment"""
60 sentinel = object()
61 mock_get.return_value = sentinel
62
63 err = APIError('foo')
64
65 self.assertEqual(err.debug, sentinel)
66 mock_get.assert_called_with('PISTON_MINI_CLIENT_DEBUG', False)
67
44class ExceptionFailHandlerTestCase(TestCase):68class ExceptionFailHandlerTestCase(TestCase):
45 """As this is the default fail handler, we can skip most tests"""69 """As this is the default fail handler, we can skip most tests"""
46 def test_no_status(self):70 def test_no_status(self):

Subscribers

People subscribed via source and target branches