Ensure that failing responses are logged
The boolean value of a failed response is False and so the way we populate the log output does not work when the request failed. When logging check that a response is not None rather than simply checking it's boolean value. Change-Id: I07fb46f156fdf8267fd3d4dc7c587cd604838d73 Closes-Bug: #1451625
This commit is contained in:
@@ -201,7 +201,7 @@ class Session(object):
|
||||
if not logger.isEnabledFor(logging.DEBUG):
|
||||
return
|
||||
|
||||
if response:
|
||||
if response is not None:
|
||||
if not status_code:
|
||||
status_code = response.status_code
|
||||
if not headers:
|
||||
|
@@ -174,6 +174,18 @@ class SessionTests(utils.TestCase):
|
||||
self.assertEqual(v, resp.headers[k])
|
||||
self.assertNotIn(v, self.logger.output)
|
||||
|
||||
def test_logs_failed_output(self):
|
||||
"""Test that output is logged even for failed requests"""
|
||||
|
||||
session = client_session.Session()
|
||||
body = uuid.uuid4().hex
|
||||
|
||||
self.stub_url('GET', text=body, status_code=400)
|
||||
resp = session.get(self.TEST_URL, raise_exc=False)
|
||||
|
||||
self.assertEqual(resp.status_code, 400)
|
||||
self.assertIn(body, self.logger.output)
|
||||
|
||||
def test_logging_cacerts(self):
|
||||
path_to_certs = '/path/to/certs'
|
||||
session = client_session.Session(verify=path_to_certs)
|
||||
|
Reference in New Issue
Block a user