diff options
author | jola-mirecka <jola.mirecka@hp.com> | 2013-03-05 16:56:02 +0000 |
---|---|---|
committer | jola-mirecka <jola.mirecka@hp.com> | 2013-03-06 15:38:50 +0000 |
commit | d90b768e509e41a2ab4f8d26b1093fd329167102 (patch) | |
tree | bfbcef8b04924980a1ad72374a43a3f5d51b5564 /tests/test_swiftclient.py | |
parent | 999e1c0f02ab4f697a0bf66c95f1744c86dc4523 (diff) | |
download | python-swiftclient-d90b768e509e41a2ab4f8d26b1093fd329167102.tar.gz |
Enhance put_object to inform when chunk is ignored
Changed documentation for chunk_size parameter to indicate
that it can be used only with file like objects.
Also added a UserWarning when using a string contents to inform
that chunk_size will be ignored.
Added a unit test to check whether the warning is working
correctly.
Fixes: bug #1147232
Change-Id: I618ec45520ba81905ce2ead4d61f192d21ae3489
Diffstat (limited to 'tests/test_swiftclient.py')
-rw-r--r-- | tests/test_swiftclient.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py index 8f147f8..8e4289e 100644 --- a/tests/test_swiftclient.py +++ b/tests/test_swiftclient.py @@ -17,6 +17,7 @@ import socket import StringIO import testtools +import warnings from urlparse import urlparse # TODO: mock http connection class with more control over headers @@ -472,6 +473,26 @@ class TestPutObject(MockHttpTest): self.assertTrue("a-b: .x:yz mn:fg:lp" in resp.buffer[0], "[a-b: .x:yz mn:fg:lp] header is missing") + def test_chunk_warning(self): + conn = c.http_connection('http://www.test.com/') + file = StringIO.StringIO('asdf') + args = ('asdf', 'asdf', 'asdf', 'asdf', file) + resp = MockHttpResponse() + conn[1].getresponse = resp.fake_response + conn[1].send = resp.fake_send + with warnings.catch_warnings(record=True) as w: + c.put_object(*args, chunk_size=20, headers={}, http_conn=conn) + self.assertEquals(len(w), 0) + + body = 'c' * 60 + c.http_connection = self.fake_http_connection(200, body=body) + args = ('http://www.test.com', 'asdf', 'asdf', 'asdf', 'asdf') + with warnings.catch_warnings(record=True) as w: + c.put_object(*args, chunk_size=20) + self.assertEquals(len(w), 1) + self.assertTrue(issubclass(w[-1].category, UserWarning)) + + def test_server_error(self): body = 'c' * 60 c.http_connection = self.fake_http_connection(500, body=body) |