Skip to content

Commit cf86155

Browse files
author
Tyson Holub
committed
changes per PR comments
1 parent 823c067 commit cf86155

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

python_http_client/client.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
class Response(object):
2121
"""Holds the response from an API call."""
2222

23-
def __init__(self, response, method):
23+
def __init__(self, response):
2424
"""
2525
:param response: The return value from a open call
2626
on a urllib.build_opener()
@@ -29,14 +29,6 @@ def __init__(self, response, method):
2929
self._status_code = response.getcode()
3030
self._body = response.read()
3131
self._headers = response.info()
32-
self._method = method
33-
34-
@property
35-
def method(self):
36-
"""
37-
:return: string, method of API call
38-
"""
39-
return self._method
4032

4133
@property
4234
def status_code(self):
@@ -181,15 +173,14 @@ def _make_request(self, opener, request, timeout=None):
181173
"""
182174
timeout = timeout or self.timeout
183175
try:
184-
return (opener.open(request, timeout=timeout),
185-
request.get_method())
176+
return opener.open(request, timeout=timeout)
186177
except HTTPError as err:
187-
exc = handle_error(err)
188-
exc.__cause__ = None
189-
_logger.info('{method} Response: {status} {body}'.format(
178+
_logger.debug('{method} Response: {status} {body}'.format(
190179
method=request.get_method(),
191180
status=exc.status_code,
192181
body=exc.body))
182+
exc = handle_error(err)
183+
exc.__cause__ = None
193184
raise exc
194185

195186
def _(self, name):
@@ -272,20 +263,19 @@ def http_request(
272263
data=data,
273264
)
274265
request.get_method = lambda: method
275-
timeout = kwargs.pop('timeout', None)
276-
_logger.info('{method} Request: {url}'.format(
266+
_logger.debug('{method} Request: {url}'.format(
277267
method=request.get_method(),
278268
url=request.get_full_url()))
279269
if request.data:
280-
_logger.info('PAYLOAD: {data}'.format(
270+
_logger.debug('PAYLOAD: {data}'.format(
281271
data=request.data))
282-
_logger.info('HEADERS: {headers}'.format(
272+
_logger.debug('HEADERS: {headers}'.format(
283273
headers=request.headers))
284274
response = Response(
285-
*self._make_request(opener, request, timeout=timeout)
275+
self._make_request(opener, request, timeout=timeout)
286276
)
287-
_logger.info('{method} Response: {status} {body}'.format(
288-
method=response.method,
277+
_logger.debug('{method} Response: {status} {body}'.format(
278+
method=method,
289279
status=response.status_code,
290280
body=response.body))
291281
return response

tests/test_unit.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, host, response_code, timeout=None):
5959

6060
def _make_request(self, opener, request, timeout=None):
6161
if 200 <= self.response_code < 299: # if successful code
62-
return MockResponse(self.response_code), request.get_method()
62+
return MockResponse(self.response_code)
6363
else:
6464
raise handle_error(MockException(self.response_code))
6565

@@ -165,29 +165,24 @@ def test__getattr__(self):
165165
mock_client._url_path += ['test']
166166
r = mock_client.get()
167167
self.assertEqual(r.status_code, 200)
168-
self.assertEqual(r.method, 'GET')
169168

170169
# Test POST
171170
r = mock_client.put()
172171
self.assertEqual(r.status_code, 200)
173-
self.assertEqual(r.method, 'PUT')
174172

175173
# Test PATCH
176174
r = mock_client.patch()
177175
self.assertEqual(r.status_code, 200)
178-
self.assertEqual(r.method, 'PATCH')
179176

180177
# Test POST
181178
mock_client.response_code = 201
182179
r = mock_client.post()
183180
self.assertEqual(r.status_code, 201)
184-
self.assertEqual(r.method, 'POST')
185181

186182
# Test DELETE
187183
mock_client.response_code = 204
188184
r = mock_client.delete()
189185
self.assertEqual(r.status_code, 204)
190-
self.assertEqual(r.method, 'DELETE')
191186

192187
mock_client.response_code = 400
193188
self.assertRaises(BadRequestsError, mock_client.get)

0 commit comments

Comments
 (0)