summaryrefslogtreecommitdiff
path: root/tests/unit/utils.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2016-01-18 17:05:28 -0800
committerTim Burke <tim.burke@gmail.com>2016-03-03 17:16:33 +0000
commit9b8ab67a780416508b995adafb07e96ea646d6f8 (patch)
treee8b1b580a0e2e2d9dc941924f408966da4ffdfe5 /tests/unit/utils.py
parentcd3a4dbf0adce0b7a6779755caaf36a0e983e5fb (diff)
downloadpython-swiftclient-9b8ab67a780416508b995adafb07e96ea646d6f8.tar.gz
Include response headers in ClientExceptions
Now, client applications can get to things like transaction IDs for failures without needing to turn on all of logging. While we're at it, add a from_response factory method for ClientException. Co-Authored-By: Alexander Corwin <ancorwin@gmail.com> Change-Id: Ib46d5f8fc7f36f651f5908bb9d900316fdaebce3
Diffstat (limited to 'tests/unit/utils.py')
-rw-r--r--tests/unit/utils.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/tests/unit/utils.py b/tests/unit/utils.py
index 1bfa8da..3b043bc 100644
--- a/tests/unit/utils.py
+++ b/tests/unit/utils.py
@@ -87,17 +87,19 @@ def fake_http_connect(*code_iter, **kwargs):
def __init__(self, status, etag=None, body='', timestamp='1',
headers=None):
- self.status = status
+ self.status_code = self.status = status
self.reason = 'Fake'
+ self.scheme = 'http'
self.host = '1.2.3.4'
self.port = '1234'
self.sent = 0
self.received = 0
self.etag = etag
- self.body = body
+ self.content = self.body = body
self.timestamp = timestamp
self._is_closed = True
self.headers = headers or {}
+ self.request = None
def getresponse(self):
if kwargs.get('raise_exc'):
@@ -223,15 +225,18 @@ class MockHttpTest(unittest.TestCase):
pass
conn = RequestsWrapper()
- def request(method, url, *args, **kwargs):
+ def request(method, path, *args, **kwargs):
try:
conn.resp = self.fake_connect()
except StopIteration:
self.fail('Unexpected %s request for %s' % (
- method, url))
- self.request_log.append((parsed, method, url, args,
+ method, path))
+ self.request_log.append((parsed, method, path, args,
kwargs, conn.resp))
conn.host = conn.resp.host
+ conn.resp.request = RequestsWrapper()
+ conn.resp.request.url = '%s://%s%s' % (
+ conn.resp.scheme, conn.resp.host, path)
conn.resp.has_been_read = False
_orig_read = conn.resp.read
@@ -240,15 +245,15 @@ class MockHttpTest(unittest.TestCase):
return _orig_read(*args, **kwargs)
conn.resp.read = read
if on_request:
- status = on_request(method, url, *args, **kwargs)
+ status = on_request(method, path, *args, **kwargs)
conn.resp.status = status
if auth_token:
headers = args[1]
self.assertEqual(auth_token,
headers.get('X-Auth-Token'))
if query_string:
- self.assertTrue(url.endswith('?' + query_string))
- if url.endswith('invalid_cert') and not insecure:
+ self.assertTrue(path.endswith('?' + query_string))
+ if path.endswith('invalid_cert') and not insecure:
from swiftclient import client as c
raise c.ClientException("invalid_certificate")
if exc: