diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-06-04 12:08:07 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-06-04 12:08:07 +0000 |
commit | ec3e2ab3a099b1276ae5d87fda936567f64423dc (patch) | |
tree | bd2d542f8a371ecc9dc050b158f1183683e19e95 /tests/unit/test_swiftclient.py | |
parent | f0cc3be2ac2cb6474ba117da323f6369c1e6c791 (diff) | |
parent | b6457e0f95c2563f745bbfb64c739929bc0dc901 (diff) | |
download | python-swiftclient-ec3e2ab3a099b1276ae5d87fda936567f64423dc.tar.gz |
Merge "Allow reading from object body on download"
Diffstat (limited to 'tests/unit/test_swiftclient.py')
-rw-r--r-- | tests/unit/test_swiftclient.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py index b90d99c..ae46099 100644 --- a/tests/unit/test_swiftclient.py +++ b/tests/unit/test_swiftclient.py @@ -685,6 +685,41 @@ class TestGetObject(MockHttpTest): }), ]) + def test_chunk_size_read_method(self): + conn = c.Connection('http://auth.url/', 'some_user', 'some_key') + with mock.patch('swiftclient.client.get_auth_1_0') as mock_get_auth: + mock_get_auth.return_value = ('http://auth.url/', 'tToken') + c.http_connection = self.fake_http_connection(200, body='abcde') + __, resp = conn.get_object('asdf', 'asdf', resp_chunk_size=3) + self.assertTrue(hasattr(resp, 'read')) + self.assertEquals(resp.read(3), 'abc') + self.assertEquals(resp.read(None), 'de') + self.assertEquals(resp.read(), '') + + def test_chunk_size_iter(self): + conn = c.Connection('http://auth.url/', 'some_user', 'some_key') + with mock.patch('swiftclient.client.get_auth_1_0') as mock_get_auth: + mock_get_auth.return_value = ('http://auth.url/', 'tToken') + c.http_connection = self.fake_http_connection(200, body='abcde') + __, resp = conn.get_object('asdf', 'asdf', resp_chunk_size=3) + self.assertTrue(hasattr(resp, 'next')) + self.assertEquals(next(resp), 'abc') + self.assertEquals(next(resp), 'de') + self.assertRaises(StopIteration, next, resp) + + def test_chunk_size_read_and_iter(self): + conn = c.Connection('http://auth.url/', 'some_user', 'some_key') + with mock.patch('swiftclient.client.get_auth_1_0') as mock_get_auth: + mock_get_auth.return_value = ('http://auth.url/', 'tToken') + c.http_connection = self.fake_http_connection(200, body='abcdef') + __, resp = conn.get_object('asdf', 'asdf', resp_chunk_size=2) + self.assertTrue(hasattr(resp, 'read')) + self.assertEquals(resp.read(3), 'abc') + self.assertEquals(next(resp), 'de') + self.assertEquals(resp.read(), 'f') + self.assertRaises(StopIteration, next, resp) + self.assertEquals(resp.read(), '') + class TestHeadObject(MockHttpTest): |