diff options
author | Leah Klearman <lklrmn@gmail.com> | 2013-10-15 09:46:46 -0700 |
---|---|---|
committer | Leah Klearman <lklrmn@gmail.com> | 2013-10-17 16:05:36 -0700 |
commit | b682935055fccbbbad988e75679dfc01b0869622 (patch) | |
tree | 11032fcf3f16315286f539e83032254335b2681a /tests/test_swiftclient.py | |
parent | e08ec3ab8a28facc95977fc25c7e1e5381507591 (diff) | |
download | python-swiftclient-b682935055fccbbbad988e75679dfc01b0869622.tar.gz |
enhance swiftclient logging
* log to debug for successes and info for errors
* remove dead code, neither body or raw_body are sent in kwargs
* include resp.reason and response headers in logging
* remove trailing \n in logging. users who want them can set logging.basicConfig(format=FORMAT)
* add --info option to swift cli
Change-Id: If07af46cb377f3f3d70f6c4284037241d360a8b7
Diffstat (limited to 'tests/test_swiftclient.py')
-rw-r--r-- | tests/test_swiftclient.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py index 6cf3c11..e827a2a 100644 --- a/tests/test_swiftclient.py +++ b/tests/test_swiftclient.py @@ -16,6 +16,7 @@ # TODO: More tests import mock import httplib +import logging import socket import StringIO import testtools @@ -159,6 +160,7 @@ class MockHttpTest(testtools.TestCase): class MockHttpResponse(): def __init__(self): self.status = 200 + self.reason = "OK" self.buffer = [] def read(self): @@ -167,6 +169,9 @@ class MockHttpResponse(): def getheader(self, name, default): return "" + def getheaders(self): + return {"key1": "value1", "key2": "value2"} + def fake_response(self): return MockHttpResponse() @@ -838,6 +843,9 @@ class TestConnection(MockHttpTest): def getheader(self, *args, **kwargs): return 'header' + def getheaders(self): + return {"key1": "value1", "key2": "value2"} + def read(self, *args, **kwargs): return '' @@ -883,5 +891,52 @@ class TestConnection(MockHttpTest): c.http_connection = orig_conn +class TestLogging(MockHttpTest): + """ + Make sure all the lines in http_log are covered. + """ + + def setUp(self): + super(TestLogging, self).setUp() + self.swiftclient_logger = logging.getLogger("swiftclient") + self.log_level = self.swiftclient_logger.getEffectiveLevel() + self.swiftclient_logger.setLevel(logging.INFO) + + def tearDown(self): + self.swiftclient_logger.setLevel(self.log_level) + super(TestLogging, self).tearDown() + + def test_put_ok(self): + c.http_connection = self.fake_http_connection(200) + args = ('http://www.test.com', 'asdf', 'asdf', 'asdf', 'asdf') + value = c.put_object(*args) + self.assertTrue(isinstance(value, basestring)) + + def test_head_error(self): + c.http_connection = self.fake_http_connection(500) + self.assertRaises(c.ClientException, c.head_object, + 'http://www.test.com', 'asdf', 'asdf', 'asdf') + + def test_get_error(self): + body = 'c' * 65 + conn = self.fake_http_connection( + 404, body=body)('http://www.test.com/') + request_args = {} + + def fake_request(method, url, body=None, headers=None): + request_args['method'] = method + request_args['url'] = url + request_args['body'] = body + request_args['headers'] = headers + return + conn[1].request = fake_request + headers = {'Range': 'bytes=1-2'} + self.assertRaises( + c.ClientException, + c.get_object, + 'url_is_irrelevant', 'TOKEN', 'container', 'object', + http_conn=conn, headers=headers) + + if __name__ == '__main__': testtools.main() |