summaryrefslogtreecommitdiff
path: root/tests/unit/test_swiftclient.py
diff options
context:
space:
mode:
authorTim Burke <tim.burke@gmail.com>2015-05-18 08:05:02 -0700
committerTim Burke <tim.burke@gmail.com>2015-09-03 13:46:03 -0700
commitce569f46517e10f2ce0d27e9ee0a922ad1d84e2f (patch)
tree1a32030d29466ae4d63345d26a135abde1b12fea /tests/unit/test_swiftclient.py
parentff073ab34a10230cc78a4daa3cab2e22bf1fd17d (diff)
downloadpython-swiftclient-ce569f46517e10f2ce0d27e9ee0a922ad1d84e2f.tar.gz
Centralize header parsing
All response headers are now exposed as unicode objects. Any url-encoding is interpretted as UTF-8; if that causes decoding to fail, the url-encoded form is returned. As a result, deleting DLOs with unicode characters will no longer raise UnicodeEncodeErrors under Python 2. Related-Bug: #1431866 Change-Id: Idb111c5bf3ac1f5ccfa724b3f4ede8f37d5bfac4
Diffstat (limited to 'tests/unit/test_swiftclient.py')
-rw-r--r--tests/unit/test_swiftclient.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py
index 23b3138..2855629 100644
--- a/tests/unit/test_swiftclient.py
+++ b/tests/unit/test_swiftclient.py
@@ -130,6 +130,31 @@ class TestHttpHelpers(MockHttpTest):
value = u'unicode:\xe9\u20ac'
self.assertEqual('unicode%3A%C3%A9%E2%82%AC', c.quote(value))
+ def test_parse_header_string(self):
+ value = b'bytes'
+ self.assertEqual(u'bytes', c.parse_header_string(value))
+ value = u'unicode:\xe9\u20ac'
+ self.assertEqual(u'unicode:\xe9\u20ac', c.parse_header_string(value))
+ value = 'native%20string'
+ self.assertEqual(u'native string', c.parse_header_string(value))
+
+ value = b'encoded%20bytes%E2%82%AC'
+ self.assertEqual(u'encoded bytes\u20ac', c.parse_header_string(value))
+ value = 'encoded%20unicode%E2%82%AC'
+ self.assertEqual(u'encoded unicode\u20ac',
+ c.parse_header_string(value))
+
+ value = b'bad%20bytes%ff%E2%82%AC'
+ self.assertEqual(u'bad%20bytes%ff%E2%82%AC',
+ c.parse_header_string(value))
+ value = u'bad%20unicode%ff\u20ac'
+ self.assertEqual(u'bad%20unicode%ff\u20ac',
+ c.parse_header_string(value))
+
+ value = b'really%20bad\xffbytes'
+ self.assertEqual(u'really%2520bad%FFbytes',
+ c.parse_header_string(value))
+
def test_http_connection(self):
url = 'http://www.test.com'
_junk, conn = c.http_connection(url)
@@ -686,6 +711,18 @@ class TestGetObject(MockHttpTest):
}),
])
+ def test_response_headers(self):
+ c.http_connection = self.fake_http_connection(
+ 200, headers={'X-Utf-8-Header': b't%c3%a9st',
+ 'X-Non-Utf-8-Header': b'%ff',
+ 'X-Binary-Header': b'\xff'})
+ conn = c.http_connection('http://www.test.com')
+ headers, data = c.get_object('url_is_irrelevant', 'TOKEN',
+ 'container', 'object', http_conn=conn)
+ self.assertEqual(u't\xe9st', headers.get('x-utf-8-header', ''))
+ self.assertEqual(u'%ff', headers.get('x-non-utf-8-header', ''))
+ self.assertEqual(u'%FF', headers.get('x-binary-header', ''))
+
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: