Fix incorrect method when creating unicode env

It is better to use 'unicode' method to parse
env name to string when call env creating API.

Closes-Bug: 1443350

Change-Id: I2fbce6c68ce71f9607d261a01e3a913ddefd5725
This commit is contained in:
Li Xipeng 2015-05-09 13:24:16 +08:00
parent bc97c04019
commit efee9edbfb
2 changed files with 18 additions and 3 deletions

View File

@ -52,10 +52,10 @@ class Controller(object):
@request_statistics.stats_count(API_NAME, 'Create')
def create(self, request, body):
LOG.debug('Environments:Create <Body {0}>'.format(body))
LOG.debug(u'Environments:Create <Body {0}>'.format(body))
policy.check('create_environment', request.context)
LOG.debug('ENV NAME: {0}>'.format(body['name']))
if VALID_NAME_REGEX.match(str(body['name'])):
name = unicode(body['name'])
if VALID_NAME_REGEX.match(name):
try:
environment = envs.EnvironmentServices.create(
body.copy(),

View File

@ -1,3 +1,4 @@
# coding: utf-8
# Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@ -112,6 +113,20 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
result = req.get_response(self.api)
self.assertEqual(400, result.status_code)
def test_unicode_environment_name_create(self):
"""Check that an unicode env name results in an HTTPClientError."""
self._set_policy_rules(
{'list_environments': '@',
'create_environment': '@',
'show_environment': '@'}
)
self.expect_policy_check('create_environment')
body = {'name': u'yaql ♥ unicode'.encode('utf-8')}
req = self._post('/environments', json.dumps(body))
result = req.get_response(self.api)
self.assertEqual(400, result.status_code)
def test_missing_environment(self):
"""Check that a missing environment results in an HTTPNotFound."""
self._set_policy_rules(