Fixing unicode issue when to_dict is called on py2.7 env
When using non-unicode old style user id such as Gāo
Unicode error popup on py2.7 environment
Fixing it on common/context.py
Change-Id: I95e49f359410049ff5b254cd1b8ee16402c8719d
Closes-Bug: #1761629
(cherry picked from commit 4d71926b3a
)
This commit is contained in:
parent
825731d81b
commit
b76d18730d
|
@ -156,8 +156,8 @@ class RequestContext(context.RequestContext):
|
|||
return self._clients
|
||||
|
||||
def to_dict(self):
|
||||
user_idt = '{user} {tenant}'.format(user=self.user_id or '-',
|
||||
tenant=self.tenant_id or '-')
|
||||
user_idt = u'{user} {tenant}'.format(user=self.user_id or '-',
|
||||
tenant=self.tenant_id or '-')
|
||||
|
||||
return {'auth_token': self.auth_token,
|
||||
'username': self.username,
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
|
@ -78,6 +79,51 @@ class TestRequestContext(common.HeatTestCase):
|
|||
del(ctx_dict['request_id'])
|
||||
self.assertEqual(self.ctx, ctx_dict)
|
||||
|
||||
def test_request_context_to_dict_unicode(self):
|
||||
|
||||
ctx_origin = {'username': 'mick',
|
||||
'trustor_user_id': None,
|
||||
'auth_token': '123',
|
||||
'auth_token_info': {'123info': 'woop'},
|
||||
'is_admin': False,
|
||||
'user': 'mick',
|
||||
'password': 'foo',
|
||||
'trust_id': None,
|
||||
'global_request_id': None,
|
||||
'show_deleted': False,
|
||||
'roles': ['arole', 'notadmin'],
|
||||
'tenant_id': '456tenant',
|
||||
'user_id': u'Gāo',
|
||||
'tenant': u'\u5218\u80dc',
|
||||
'auth_url': 'http://xyz',
|
||||
'aws_creds': 'blah',
|
||||
'region_name': 'RegionOne',
|
||||
'user_identity': u'Gāo 456tenant',
|
||||
'user_domain': None,
|
||||
'project_domain': None}
|
||||
|
||||
ctx = context.RequestContext(
|
||||
auth_token=ctx_origin.get('auth_token'),
|
||||
username=ctx_origin.get('username'),
|
||||
password=ctx_origin.get('password'),
|
||||
aws_creds=ctx_origin.get('aws_creds'),
|
||||
project_name=ctx_origin.get('tenant'),
|
||||
tenant=ctx_origin.get('tenant_id'),
|
||||
user=ctx_origin.get('user_id'),
|
||||
auth_url=ctx_origin.get('auth_url'),
|
||||
roles=ctx_origin.get('roles'),
|
||||
show_deleted=ctx_origin.get('show_deleted'),
|
||||
is_admin=ctx_origin.get('is_admin'),
|
||||
auth_token_info=ctx_origin.get('auth_token_info'),
|
||||
trustor_user_id=ctx_origin.get('trustor_user_id'),
|
||||
trust_id=ctx_origin.get('trust_id'),
|
||||
region_name=ctx_origin.get('region_name'),
|
||||
user_domain_id=ctx_origin.get('user_domain'),
|
||||
project_domain_id=ctx_origin.get('project_domain'))
|
||||
ctx_dict = ctx.to_dict()
|
||||
del(ctx_dict['request_id'])
|
||||
self.assertEqual(ctx_origin, ctx_dict)
|
||||
|
||||
def test_request_context_from_dict(self):
|
||||
ctx = context.RequestContext.from_dict(self.ctx)
|
||||
ctx_dict = ctx.to_dict()
|
||||
|
|
Loading…
Reference in New Issue