Files
glance_store/tests/unit/test_utils.py
Zhi Yan Liu 03331b19f3 Adding common.utils.exception_to_str() to avoid encoding issue
1. Ported common.utils.exception_to_str() back to glance_store.
2. Used exception_to_str() to consistently cast the exception to avoid
potential encoding issue.

Change-Id: I398ea0e218ebb37b9041cfe82f18b11e614662bf
Related-Id: I77478a8eeeefd85bf98138156429df53d0a4c079
Signed-off-by: Zhi Yan Liu <zhiyanl@cn.ibm.com>
2014-09-19 11:19:34 +00:00

38 lines
1.3 KiB
Python

# Copyright 2014 OpenStack Foundation
# All Rights Reserved.
#
# 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
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from oslotest import base
from glance_store.common import utils
class TestUtils(base.BaseTestCase):
"""Test routines in glance_store.common.utils"""
def test_exception_to_str(self):
class FakeException(Exception):
def __str__(self):
raise UnicodeError()
ret = utils.exception_to_str(Exception('error message'))
self.assertEqual(ret, 'error message')
ret = utils.exception_to_str(Exception('\xa5 error message'))
self.assertEqual(ret, ' error message')
ret = utils.exception_to_str(FakeException('\xa5 error message'))
self.assertEqual(ret, "Caught '%(exception)s' exception." %
{'exception': 'FakeException'})