diff options
author | Jenkins <jenkins@review.openstack.org> | 2016-01-06 00:06:04 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2016-01-06 00:06:04 +0000 |
commit | 81003b8d993dc61ef19c6fc4cbe60d9fda76b4d1 (patch) | |
tree | d7a5e754218cf352a292d7b364141b1c040a5974 /tests/unit/test_swiftclient.py | |
parent | 62bfe10f58ce777a1b70549a641528b88f94f246 (diff) | |
parent | 39b1a31d8a187534f54e32e9aec2cb2bb839a390 (diff) | |
download | python-swiftclient-81003b8d993dc61ef19c6fc4cbe60d9fda76b4d1.tar.gz |
Merge "Wrap raw iterators to ensure we send entire contents to server"
Diffstat (limited to 'tests/unit/test_swiftclient.py')
-rw-r--r-- | tests/unit/test_swiftclient.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py index e837288..60f65c9 100644 --- a/tests/unit/test_swiftclient.py +++ b/tests/unit/test_swiftclient.py @@ -984,6 +984,26 @@ class TestPutObject(MockHttpTest): data += chunk self.assertEqual(data, raw_data) + def test_iter_upload(self): + def data(): + for chunk in ('foo', '', 'bar'): + yield chunk + conn = c.http_connection(u'http://www.test.com/') + resp = MockHttpResponse(status=200) + conn[1].getresponse = resp.fake_response + conn[1]._request = resp._fake_request + + c.put_object(url='http://www.test.com', http_conn=conn, + contents=data()) + req_headers = resp.requests_params['headers'] + self.assertNotIn('Content-Length', req_headers) + req_data = resp.requests_params['data'] + self.assertTrue(hasattr(req_data, '__iter__')) + # If we emit an empty chunk, requests will go ahead and send it, + # causing the server to close the connection. So make sure we don't + # do that. + self.assertEqual(['foo', 'bar'], list(req_data)) + def test_md5_mismatch(self): conn = c.http_connection('http://www.test.com') resp = MockHttpResponse(status=200, verify=True, |