Merge "Fix unicode issues with Python 3"

This commit is contained in:
Zuul 2017-11-22 03:11:07 +00:00 committed by Gerrit Code Review
commit d75ff38dda
6 changed files with 18 additions and 10 deletions

View File

@ -15,6 +15,8 @@
import json
import six
from blazar import context
from blazar import exceptions
@ -34,5 +36,5 @@ def ctx_from_headers(headers):
service_catalog=service_catalog,
user_name=headers['X-User-Name'],
project_name=headers['X-Project-Name'],
roles=map(unicode.strip, headers['X-Roles'].split(',')),
roles=map(six.text_type.strip, headers['X-Roles'].split(',')),
)

View File

@ -28,12 +28,13 @@ down_revision = None
import uuid
from alembic import op
import six
import sqlalchemy as sa
from sqlalchemy.dialects.mysql import MEDIUMTEXT
def _generate_unicode_uuid():
return unicode(str(uuid.uuid4()))
return six.text_type(str(uuid.uuid4()))
def MediumText():

View File

@ -17,6 +17,7 @@
# FIXME: https://bugs.launchpad.net/climate/+bug/1300132
# from oslo_log import log as logging
from oslo_utils import uuidutils
import six
import sqlalchemy as sa
from sqlalchemy.dialects.mysql import MEDIUMTEXT
from sqlalchemy.orm import relationship
@ -29,7 +30,7 @@ from blazar.db.sqlalchemy import model_base as mb
def _generate_unicode_uuid():
return unicode(uuidutils.generate_uuid())
return six.text_type(uuidutils.generate_uuid())
def MediumText():

View File

@ -18,6 +18,7 @@ import datetime
from oslo_context import context
from oslo_utils import uuidutils
import six
from blazar.db.sqlalchemy import api as db_api
from blazar.db.sqlalchemy import utils as db_utils
@ -25,7 +26,7 @@ from blazar import tests
def _get_fake_random_uuid():
return unicode(uuidutils.generate_uuid())
return six.text_type(uuidutils.generate_uuid())
def _get_fake_lease_uuid():

View File

@ -17,6 +17,7 @@ import datetime
import uuid
import mock
import six
from blazar import context
from blazar.db import api as db_api
@ -54,7 +55,7 @@ class TestVirtualInstancePlugin(tests.TestCase):
}
def get_uuid(self):
return unicode(str(uuid.uuid4()))
return six.text_type(str(uuid.uuid4()))
def generate_basic_events(self, lease_id, start, before_end, end):
return [

View File

@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import six
from blazar import exceptions
from blazar import tests
@ -23,10 +25,10 @@ class BlazarExceptionTestCase(tests.TestCase):
msg_fmt = "default message"
exc = FakeBlazarException()
self.assertEqual(unicode(exc), 'default message')
self.assertEqual(six.text_type(exc), 'default message')
def test_error_msg(self):
self.assertEqual(unicode(exceptions.BlazarException('test')),
self.assertEqual(six.text_type(exceptions.BlazarException('test')),
'test')
def test_default_error_msg_with_kwargs(self):
@ -34,7 +36,7 @@ class BlazarExceptionTestCase(tests.TestCase):
msg_fmt = "default message: %(code)s"
exc = FakeBlazarException(code=500)
self.assertEqual(unicode(exc), 'default message: 500')
self.assertEqual(six.text_type(exc), 'default message: 500')
self.assertEqual(exc.message, 'default message: 500')
def test_error_msg_exception_with_kwargs(self):
@ -42,7 +44,7 @@ class BlazarExceptionTestCase(tests.TestCase):
msg_fmt = "default message: %(mispelled_code)s"
exc = FakeBlazarException(code=500, mispelled_code='blah')
self.assertEqual(unicode(exc), 'default message: blah')
self.assertEqual(six.text_type(exc), 'default message: blah')
self.assertEqual(exc.message, 'default message: blah')
def test_default_error_code(self):
@ -61,6 +63,6 @@ class BlazarExceptionTestCase(tests.TestCase):
def test_policynotauthorized_exception(self):
exc = exceptions.PolicyNotAuthorized(action='foo')
self.assertEqual(unicode(exc.message),
self.assertEqual(six.text_type(exc.message),
"Policy doesn't allow foo to be performed")
self.assertEqual(exc.kwargs['code'], 403)