summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-09-19 23:53:30 +0000
committerGerrit Code Review <review@openstack.org>2014-09-19 23:53:30 +0000
commit692a6cdc6ec516f3cd5fdc600e20c6cb6fc3ca6d (patch)
tree1e6c18eb7bb6f6a454f01013cf880e57dee1c255 /tests/unit
parent578299499cc8836f6a2c9d10850928d547055dca (diff)
parent03331b19f327234d7f8f060d0cd361b2e36330c1 (diff)
downloadglance_store-692a6cdc6ec516f3cd5fdc600e20c6cb6fc3ca6d.tar.gz
Merge "Adding common.utils.exception_to_str() to avoid encoding issue"
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_store_base.py23
-rw-r--r--tests/unit/test_swift_store.py3
-rw-r--r--tests/unit/test_utils.py37
3 files changed, 39 insertions, 24 deletions
diff --git a/tests/unit/test_store_base.py b/tests/unit/test_store_base.py
index 4fcaf11..8b9c408 100644
--- a/tests/unit/test_store_base.py
+++ b/tests/unit/test_store_base.py
@@ -14,8 +14,6 @@
# under the License.
import glance_store as store
-from glance_store import driver
-from glance_store.openstack.common.gettextutils import _
from glance_store.tests import base
@@ -25,27 +23,6 @@ class TestStoreBase(base.StoreBaseTest):
super(TestStoreBase, self).setUp()
self.config(default_store='file', group='glance_store')
- def test_exception_to_unicode(self):
- class FakeException(Exception):
- def __str__(self):
- raise UnicodeError()
-
- exc = Exception('error message')
- ret = driver._exception_to_unicode(exc)
- self.assertIsInstance(ret, unicode)
- self.assertEqual(ret, 'error message')
-
- exc = Exception('\xa5 error message')
- ret = driver._exception_to_unicode(exc)
- self.assertIsInstance(ret, unicode)
- self.assertEqual(ret, ' error message')
-
- exc = FakeException('\xa5 error message')
- ret = driver._exception_to_unicode(exc)
- self.assertIsInstance(ret, unicode)
- self.assertEqual(ret, _("Caught '%(exception)s' exception.") %
- {'exception': 'FakeException'})
-
def test_create_store_exclude_unconfigurable_drivers(self):
self.config(stores=["no_conf", "file"], group='glance_store')
count = store.create_stores(self.conf)
diff --git a/tests/unit/test_swift_store.py b/tests/unit/test_swift_store.py
index 09ef402..f6b4715 100644
--- a/tests/unit/test_swift_store.py
+++ b/tests/unit/test_swift_store.py
@@ -33,6 +33,7 @@ from glance_store._drivers.swift import utils as sutils
from glance_store import backend
from glance_store import BackendException
from glance_store.common import auth
+from glance_store.common import utils
from glance_store import exceptions
from glance_store.location import get_location_from_uri
from glance_store.openstack.common import context
@@ -479,7 +480,7 @@ class SwiftTests(object):
except BackendException as e:
exception_caught = True
self.assertIn("container noexist does not exist "
- "in Swift", unicode(e))
+ "in Swift", utils.exception_to_str(e))
self.assertTrue(exception_caught)
self.assertEqual(SWIFT_PUT_OBJECT_CALLS, 0)
diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py
new file mode 100644
index 0000000..f08345e
--- /dev/null
+++ b/tests/unit/test_utils.py
@@ -0,0 +1,37 @@
+# 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'})