summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeyeong Kim <seyeong.kim@canonical.com>2018-04-05 15:10:01 -0700
committerSeyeong Kim <seyeong.kim@canonical.com>2018-04-19 18:19:50 -0700
commitc4968824dbeaad849d16482cc7a6234e862714c6 (patch)
tree2720f1d0a6ca7932b77c7c8e577a69bce54206e9
parent6fed8321538bad3b14a09162e84ed5066cb9e2d9 (diff)
downloadheat-c4968824dbeaad849d16482cc7a6234e862714c6.tar.gz
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 4d71926b3afc50c3f16378de260b86a85e8d721d)
-rw-r--r--heat/common/context.py4
-rw-r--r--heat/tests/test_common_context.py46
2 files changed, 48 insertions, 2 deletions
diff --git a/heat/common/context.py b/heat/common/context.py
index 974ee815f..ad89c83f6 100644
--- a/heat/common/context.py
+++ b/heat/common/context.py
@@ -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,
diff --git a/heat/tests/test_common_context.py b/heat/tests/test_common_context.py
index 9f66d9e0d..0fb8f9d4e 100644
--- a/heat/tests/test_common_context.py
+++ b/heat/tests/test_common_context.py
@@ -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()