Merge "Fix adding non-ascii attrs to Resource objects error"
This commit is contained in:
@@ -31,6 +31,7 @@ import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from cinderclient.apiclient import exceptions
|
||||
from oslo_utils import encodeutils
|
||||
from oslo_utils import strutils
|
||||
|
||||
|
||||
@@ -496,7 +497,7 @@ class Resource(RequestIdMixin):
|
||||
# In this case we already defined the attribute on the class
|
||||
continue
|
||||
except UnicodeEncodeError:
|
||||
pass
|
||||
setattr(self, encodeutils.safe_encode(k), v)
|
||||
self._info[k] = v
|
||||
|
||||
def __getattr__(self, k):
|
||||
|
@@ -48,6 +48,16 @@ class BaseTest(utils.TestCase):
|
||||
self.assertEqual("<Resource baz=spam, foo=bar>", repr(r))
|
||||
self.assertNotIn("x_openstack_request_ids", repr(r))
|
||||
|
||||
def test_add_non_ascii_attr_to_resource(self):
|
||||
info = {'gigabytes_тест': -1,
|
||||
'volumes_тест': -1,
|
||||
'id': 'admin'}
|
||||
|
||||
res = base.Resource(None, info)
|
||||
|
||||
for key, value in info.items():
|
||||
self.assertEqual(value, getattr(res, key, None))
|
||||
|
||||
def test_getid(self):
|
||||
self.assertEqual(4, base.getid(4))
|
||||
|
||||
|
Reference in New Issue
Block a user