summaryrefslogtreecommitdiff
path: root/tests/unit/test_swiftclient.py
diff options
context:
space:
mode:
authorAlistair Coles <alistair.coles@hp.com>2015-09-22 11:09:44 +0100
committerAlistair Coles <alistair.coles@hp.com>2015-09-23 12:21:45 +0100
commit328d6a8d457b8be6fc4b3dfdbb396a44f0b8710b (patch)
tree80912300b744c57ab3f50c96630b3494fb229167 /tests/unit/test_swiftclient.py
parent7cb99d3157f24e81737463302c937f1c251b7084 (diff)
downloadpython-swiftclient-328d6a8d457b8be6fc4b3dfdbb396a44f0b8710b.tar.gz
Add tests and param definitions for headers parameter
Cleanups for change I35c3b266b3c733f6b1629de4c683ea7d40128032 Add missing param definitions to client get_container and head_object docstrings. For consistency, add headers parameter to the Connection class head_object and head_container wrapper methods. Add tests to verify that the headers parameter of Connection get_container, head_container and head_object methods is passed to the module functions. Change-Id: Ib40d5b626b2793840727c58cffbf725bea55651f
Diffstat (limited to 'tests/unit/test_swiftclient.py')
-rw-r--r--tests/unit/test_swiftclient.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py
index 410fd6f..01e393c 100644
--- a/tests/unit/test_swiftclient.py
+++ b/tests/unit/test_swiftclient.py
@@ -1708,6 +1708,59 @@ class TestConnection(MockHttpTest):
finally:
c.http_connection = orig_conn
+ def test_get_container(self):
+ headers = {'X-Favourite-Pet': 'Aardvark'}
+ with mock.patch('swiftclient.client.http_connection',
+ self.fake_http_connection(200, body=b'{}')):
+ with mock.patch('swiftclient.client.get_auth',
+ lambda *a, **k: ('http://url:8080/v1/a', 'token')):
+ conn = c.Connection()
+ conn.get_container('c1', prefix='p', limit=5,
+ headers=headers)
+ self.assertEqual(1, len(self.request_log), self.request_log)
+ self.assertRequests([
+ ('GET', '/v1/a/c1?format=json&limit=5&prefix=p', '', {
+ 'x-auth-token': 'token',
+ 'X-Favourite-Pet': 'Aardvark',
+ }),
+ ])
+ self.assertEqual(conn.attempts, 1)
+
+ def test_head_container(self):
+ headers = {'X-Favourite-Pet': 'Aardvark'}
+ with mock.patch('swiftclient.client.http_connection',
+ self.fake_http_connection(200, body=b'{}')):
+ with mock.patch('swiftclient.client.get_auth',
+ lambda *a, **k: ('http://url:8080/v1/a', 'token')):
+ conn = c.Connection()
+ conn.head_container('c1', headers=headers)
+ self.assertEqual(1, len(self.request_log), self.request_log)
+ self.assertRequests([
+ ('HEAD', '/v1/a/c1', '', {
+ 'x-auth-token': 'token',
+ 'X-Favourite-Pet': 'Aardvark',
+ }),
+ ])
+ self.assertEqual(conn.attempts, 1)
+
+ def test_head_object(self):
+ headers = {'X-Favourite-Pet': 'Aardvark'}
+ with mock.patch('swiftclient.client.http_connection',
+ self.fake_http_connection(200)):
+ with mock.patch('swiftclient.client.get_auth',
+ lambda *a, **k: ('http://url:8080/v1/a', 'token')):
+ conn = c.Connection()
+ conn.head_object('c1', 'o1',
+ headers=headers)
+ self.assertEqual(1, len(self.request_log), self.request_log)
+ self.assertRequests([
+ ('HEAD', '/v1/a/c1/o1', '', {
+ 'x-auth-token': 'token',
+ 'X-Favourite-Pet': 'Aardvark',
+ }),
+ ])
+ self.assertEqual(conn.attempts, 1)
+
class TestResponseDict(MockHttpTest):
"""