diff options
author | Tim Burke <tim.burke@gmail.com> | 2020-08-14 10:41:15 -0700 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2020-09-09 15:32:43 -0700 |
commit | 0f6713ed5b8cdcf5cbc0850dea224b41d90e63f4 (patch) | |
tree | 80f8b277aa2b91a4606e9d7b30d7f1742361b182 /test | |
parent | 9d8db8f6126542dc18ea1b14e078d64cc1a254e4 (diff) | |
download | python-swiftclient-0f6713ed5b8cdcf5cbc0850dea224b41d90e63f4.tar.gz |
Include transaction ID in ClientException.__str__
It's fairly annoying getting a traceback in swift's probe tests then
only having a URL and status code to go searching for in logs.
Leave the shell.py output untouched, though, since we output the
transaction ID on a new line anyway.
Change-Id: Idb849848ec08b6c04812b088467c9a687c2a7e27
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/test_swiftclient.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/unit/test_swiftclient.py b/test/unit/test_swiftclient.py index dfd79c7..2644e33 100644 --- a/test/unit/test_swiftclient.py +++ b/test/unit/test_swiftclient.py @@ -84,6 +84,23 @@ class TestClientException(unittest.TestCase): self.assertIs(True, hasattr(exc, key)) self.assertEqual(getattr(exc, key), value) + def test_transaction_id_from_headers(self): + exc = c.ClientException('test') + self.assertIsNone(exc.transaction_id) + + exc = c.ClientException('test', http_response_headers={}) + self.assertIsNone(exc.transaction_id) + + exc = c.ClientException('test', http_response_headers={ + 'X-Trans-Id': 'some-id'}) + self.assertEqual(exc.transaction_id, 'some-id') + self.assertIn('(txn: some-id)', str(exc)) + + exc = c.ClientException('test', http_response_headers={ + 'X-Openstack-Request-Id': 'some-other-id'}) + self.assertEqual(exc.transaction_id, 'some-other-id') + self.assertIn('(txn: some-other-id)', str(exc)) + class MockHttpResponse(object): def __init__(self, status=0, headers=None, verify=False): |