Support Unicode request_id on Python 3

The oslo.context change If48ee7f4d1c113f1f26b3b1698c6b055807b950f
will change request_id type on Python 3 from bytes to str. This
change prepares Glance for this change.

Change-Id: Ia8578ecab1b1f1bf21020c91290458efad646cd9
This commit is contained in:
Victor Stinner 2015-11-27 15:44:54 +01:00
parent 97145e66ed
commit 1e31633288
1 changed files with 8 additions and 4 deletions

View File

@ -129,8 +129,10 @@ class TestContextMiddleware(base.IsolatedUnitTest):
self.assertEqual(request_id, resp.headers['x-openstack-request-id'])
resp_req_id = resp.headers['x-openstack-request-id']
# Validate that request-id do not starts with 'req-req-'
self.assertFalse(resp_req_id.startswith(b'req-req-'))
self.assertTrue(resp_req_id.startswith(b'req-'))
if isinstance(resp_req_id, bytes):
resp_req_id = resp_req_id.decode('utf-8')
self.assertFalse(resp_req_id.startswith('req-req-'))
self.assertTrue(resp_req_id.startswith('req-'))
class TestUnauthenticatedContextMiddleware(base.IsolatedUnitTest):
@ -155,6 +157,8 @@ class TestUnauthenticatedContextMiddleware(base.IsolatedUnitTest):
middleware.process_response(resp)
self.assertEqual(request_id, resp.headers['x-openstack-request-id'])
resp_req_id = resp.headers['x-openstack-request-id']
if isinstance(resp_req_id, bytes):
resp_req_id = resp_req_id.decode('utf-8')
# Validate that request-id do not starts with 'req-req-'
self.assertFalse(resp_req_id.startswith(b'req-req-'))
self.assertTrue(resp_req_id.startswith(b'req-'))
self.assertFalse(resp_req_id.startswith('req-req-'))
self.assertTrue(resp_req_id.startswith('req-'))