summaryrefslogtreecommitdiff
path: root/tests/test_swiftclient.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@enovance.com>2014-04-02 14:34:50 +0200
committerVictor Stinner <victor.stinner@enovance.com>2014-04-04 10:57:41 +0200
commitd8cb0b9b3224012b1933529fd3d6eded38cf713e (patch)
treebf374e063ca1a39811a9129a2e9df8d1e114c31c /tests/test_swiftclient.py
parentfa65fbbce51a7a603a6453da51db41061e4388f9 (diff)
downloadpython-swiftclient-d8cb0b9b3224012b1933529fd3d6eded38cf713e.tar.gz
Python 3: fix tests on HTTP headers
HTTP headers are encoded to bytes. Store headers at (key, value) tuples instead of Unicode strings. Check also that non-ASCII Unicode headers are encoded to UTF-8. Change-Id: Ie45f5a5ba63f539a723a7ac5649779d8efb3e912
Diffstat (limited to 'tests/test_swiftclient.py')
-rw-r--r--tests/test_swiftclient.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py
index d5e1e09..e1293a9 100644
--- a/tests/test_swiftclient.py
+++ b/tests/test_swiftclient.py
@@ -170,7 +170,7 @@ class MockHttpResponse():
# This simulate previous httplib implementation that would do a
# putrequest() and then use putheader() to send header.
for k, v in kwarg['headers'].items():
- self.buffer.append('%s: %s' % (k, v))
+ self.buffer.append((k, v))
return self.fake_response()
@@ -628,7 +628,8 @@ class TestPutObject(MockHttpTest):
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
mock_file)
- headers = {'X-Header1': u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
+ text = u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91'
+ headers = {'X-Header1': text,
'X-2': 1, 'X-3': {'a': 'b'}, 'a-b': '.x:yz mn:fg:lp'}
resp = MockHttpResponse()
@@ -637,8 +638,11 @@ class TestPutObject(MockHttpTest):
value = c.put_object(*args, headers=headers, http_conn=conn)
self.assertTrue(isinstance(value, six.string_types))
# Test for RFC-2616 encoded symbols
- self.assertTrue("a-b: .x:yz mn:fg:lp" in resp.buffer[0],
- "[a-b: .x:yz mn:fg:lp] header is missing")
+ self.assertIn((b"a-b", b".x:yz mn:fg:lp"),
+ resp.buffer)
+ # Test unicode header
+ self.assertIn((b'x-header1', text.encode('utf8')),
+ resp.buffer)
def test_chunk_warning(self):
conn = c.http_connection('http://www.test.com/')
@@ -689,7 +693,8 @@ class TestPostObject(MockHttpTest):
'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91')
- headers = {'X-Header1': u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91',
+ text = u'\u5929\u7a7a\u4e2d\u7684\u4e4c\u4e91'
+ headers = {'X-Header1': text,
'X-2': '1', 'X-3': {'a': 'b'}, 'a-b': '.x:yz mn:kl:qr'}
resp = MockHttpResponse()
@@ -697,8 +702,10 @@ class TestPostObject(MockHttpTest):
conn[1]._request = resp._fake_request
c.post_object(*args, headers=headers, http_conn=conn)
# Test for RFC-2616 encoded symbols
- self.assertTrue("a-b: .x:yz mn:kl:qr" in resp.buffer[0],
- "[a-b: .x:yz mn:kl:qr] header is missing")
+ self.assertTrue((b'a-b', b"a-b: .x:yz mn:kl:qr"), resp.buffer)
+ # Test unicode header
+ self.assertIn((b'x-header1', text.encode('utf8')),
+ resp.buffer)
def test_server_error(self):
body = 'c' * 60