summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-12-06 19:43:04 +0000
committerGerrit Code Review <review@openstack.org>2012-12-06 19:43:04 +0000
commit78941d4c89b2d23930520197756d4e65e58d1749 (patch)
tree15f3cfeb78947b29aa1a357dedbe0fdbafebec82 /tests
parentec7a2ee73ffa86d0a1b9b490798d13dc53d20706 (diff)
parent15ae704d927ba2ecd97d29195d30d5587987e2ad (diff)
Merge "Allow exceptions to pass over RPC silently"
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/rpc/test_common.py53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/unit/rpc/test_common.py b/tests/unit/rpc/test_common.py
index 37d4f25..7489a8f 100644
--- a/tests/unit/rpc/test_common.py
+++ b/tests/unit/rpc/test_common.py
@@ -169,3 +169,56 @@ class RpcCommonTestCase(test_utils.BaseTestCase):
def test_queue_get_for(self):
self.assertEqual(rpc.queue_get_for(None, 'a', 'b'), 'a.b')
self.assertEqual(rpc.queue_get_for(None, 'a', None), 'a')
+
+ def test_client_exception(self):
+ e = None
+ try:
+ try:
+ raise ValueError()
+ except Exception:
+ raise rpc_common.ClientException()
+ except rpc_common.ClientException, e:
+ pass
+
+ self.assertTrue(isinstance(e, rpc_common.ClientException))
+ self.assertTrue(e._exc_info[1], ValueError)
+
+ def test_catch_client_exception(self):
+ def naughty(param):
+ int(param)
+
+ e = None
+ try:
+ rpc_common.catch_client_exception([ValueError], naughty, 'a')
+ except rpc_common.ClientException, e:
+ pass
+
+ self.assertTrue(isinstance(e, rpc_common.ClientException))
+ self.assertTrue(isinstance(e._exc_info[1], ValueError))
+
+ def test_catch_client_exception_other(self):
+ class FooException(Exception):
+ pass
+
+ def naughty():
+ raise FooException()
+
+ e = None
+ self.assertRaises(FooException,
+ rpc_common.catch_client_exception,
+ [ValueError], naughty)
+
+ def test_client_exceptions_decorator(self):
+ class FooException(Exception):
+ pass
+
+ @rpc_common.client_exceptions(FooException)
+ def naughty():
+ raise FooException()
+
+ @rpc_common.client_exceptions(FooException)
+ def really_naughty():
+ raise ValueError()
+
+ self.assertRaises(rpc_common.ClientException, naughty)
+ self.assertRaises(ValueError, really_naughty)