Merge lp://staging/~elachuni/piston-mini-client/log-to-file into lp://staging/piston-mini-client
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | 51 |
Proposed branch: | lp://staging/~elachuni/piston-mini-client/log-to-file |
Merge into: | lp://staging/piston-mini-client |
Prerequisite: | lp://staging/~elachuni/piston-mini-client/pep8-test |
Diff against target: |
302 lines (+173/-22) 6 files modified
doc/envvars.rst (+5/-1) doc/tuning.rst (+15/-0) piston_mini_client/__init__.py (+39/-3) piston_mini_client/consts.py (+1/-0) piston_mini_client/failhandlers.py (+31/-18) piston_mini_client/tests/test_log_to_file.py (+82/-0) |
To merge this branch: | bzr merge lp://staging/~elachuni/piston-mini-client/log-to-file |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Nelson | Approve | ||
Review via email: mp+100246@code.staging.launchpad.net |
Description of the change
This branch adds the ability to log all requests and responses to a file, configurable via instance setup or environment variables.
To post a comment you must log in.
On Fri, Mar 30, 2012 at 11:41 PM, Anthony Lenton
<email address hidden> wrote:
> Anthony Lenton has proposed merging lp:~elachuni/piston-mini-client/log-to-file into lp:piston-mini-client with lp:~elachuni/piston-mini-client/pep8-test as a prerequisite.
>
> This branch adds the ability to log all requests and responses to a file, configurable via instance setup or environment variables.
Excellent Anthony - this'll be very helpful!
Just one question about a test below, but all good!
> /code.launchpad .net/~elachuni/ piston- mini-client/ log-to- file/+merge/ 100246 store-developer s is requested to review the proposed merge of lp:~elachuni/piston-mini-client/log-to-file into lp:piston-mini-client. mini_client/ __init_ _.py' mini_client/ consts. py' mini_client/ failhandlers. py' mini_client/ tests/test_ log_to_ file.py' mini_client/ tests/test_ log_to_ file.py 1970-01-01 00:00:00 +0000 mini_client/ tests/test_ log_to_ file.py 2012-03-30 21:40:24 +0000 mini_client. consts import LOG_FILENAME_ENVVAR PistonAPI) : service_ root = 'http:// test.info/ api/1.0/ ' '/poke/ ', data=data, {'location' : 'ribs'}) se(TestCase) : 'httplib2. Http.request' ) are_dumped_ to_file( self, mock_request): return_ value = ({'status': '201', 'x-foo': 'bar'}, ile() as fp:
> --
> https:/
> Your team software-
>
> === modified file 'doc/envvars.rst'
> === modified file 'doc/tuning.rst'
> === modified file 'piston_
> === modified file 'piston_
> === modified file 'piston_
> === added file 'piston_
> --- piston_
> +++ piston_
> @@ -0,0 +1,82 @@
> +# -*- coding: utf-8 -*-
> +# Copyright 2010-2012 Canonical Ltd. This software is licensed under the
> +# GNU Lesser General Public License version 3 (see the file LICENSE).
> +
> +import os
> +from mock import patch
> +from tempfile import NamedTemporaryFile
> +from unittest import TestCase
> +from piston_mini_client import (
> + PistonAPI,
> + returns_json,
> +)
> +from piston_
> +
> +
> +class AnnoyAPI(
> + default_
> +
> + @returns_json
> + def poke(self, data=None):
> + return self._post(
> + extra_headers=
> +
> +
> +class LogToFileTestCa
> + @patch(
> + def test_requests_
> + mock_request.
> + '"Go away!"')
> +
> + api = AnnoyAPI()
> + with NamedTemporaryF
> + api.log_filename = fp.name
Why not initialise the api the way you've recommended in the README?
That is, with:
api = AnnoyAPI( log_filename = fp.name)
? Otherwise we're not testing that passing in the initialised value
works (although it's obvious from the current code that it does).
> + l(10, len(lines)) (lines[ 0].endswith( test.info/ api/1.0/ poke/')) l(['Content- type: application/json', (lines[ 5].endswith( 'Response: 201')) l(['x-foo: bar', '', '"Go away!"', ''], lines[6:]) 'httplib2. Http.request' ) logfile_ locat.. .
> + api.poke([1, 2, 3])
> +
> + fp.seek(0)
> + data = fp.read()
> +
> + lines = data.split('\n')
> + self.assertEqua
> + self.assertTrue
> + 'Request: POST http://
> + self.assertEqua
> + 'location: ribs', '', '[1, 2, 3]'], lines[1:5])
> + self.assertTrue
> + self.assertEqua
> +
> + @patch(
> + def test_invalid_