summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schwede <christian.schwede@enovance.com>2015-02-25 10:58:27 +0000
committerChristian Schwede <cschwede@redhat.com>2015-06-05 07:17:31 +0000
commit7f2ee7322b3f16fdd2c848be07c67107f4e065dd (patch)
tree926516b426b08e85f138132bc71d08224f5e971f
parentec3e2ab3a099b1276ae5d87fda936567f64423dc (diff)
downloadpython-swiftclient-7f2ee7322b3f16fdd2c848be07c67107f4e065dd.tar.gz
Add connection release test
This patch adds a small test to ensure a connection is released after all chunks have been consumed. It's a follow up to commit 8756591b and added to ensure there will be no regression in the future (this test fails also with that patch not applied). Change-Id: I6a6fcd26879eb2070f418c8770a395ff6c30aa51
-rw-r--r--tests/unit/test_swiftclient.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py
index ae46099..1cfe204 100644
--- a/tests/unit/test_swiftclient.py
+++ b/tests/unit/test_swiftclient.py
@@ -75,6 +75,7 @@ class MockHttpResponse(object):
self.headers = {'etag': '"%s"' % EMPTY_ETAG}
if headers:
self.headers.update(headers)
+ self.closed = False
class Raw(object):
def __init__(self, headers):
@@ -92,7 +93,7 @@ class MockHttpResponse(object):
return ""
def close(self):
- pass
+ self.closed = True
def getheader(self, name, default):
return self.headers.get(name, default)
@@ -1145,6 +1146,17 @@ class TestHTTPConnection(MockHttpTest):
conn = c.http_connection(u'http://www.test.com/', insecure=True)
self.assertEqual(conn[1].requests_args['verify'], False)
+ def test_response_connection_released(self):
+ _parsed_url, conn = c.http_connection(u'http://www.test.com/')
+ conn.resp = MockHttpResponse()
+ conn.resp.raw = mock.Mock()
+ conn.resp.raw.read.side_effect = ["Chunk", ""]
+ resp = conn.getresponse()
+ self.assertFalse(resp.closed)
+ self.assertEqual("Chunk", resp.read())
+ self.assertFalse(resp.read())
+ self.assertTrue(resp.closed)
+
class TestConnection(MockHttpTest):