summaryrefslogtreecommitdiff
path: root/designateclient/tests/test_exceptions.py
diff options
context:
space:
mode:
authorJames Li <yueli.m@gmail.com>2015-08-21 04:00:10 +0000
committerGraham Hayes <graham.hayes@hpe.com>2015-09-24 12:26:59 +0000
commit87a48c77259fb475cb0db0231cdab1b2366e3416 (patch)
treec19cdf736bc5cd8b8657cfbc23ca4dcfa176a39a /designateclient/tests/test_exceptions.py
parentf2192badc132786c1258dbb733feb451fcb9a5e6 (diff)
downloadpython-designateclient-87a48c77259fb475cb0db0231cdab1b2366e3416.tar.gz
Makes error msg more helpful
In the case that designate api returns an error response which does not have an 'message' entry, CLI will prints out nothing helpful for users. The patch grabs info from response to try to provide a helpful msg. Fixed axfr resource too. Change-Id: I810426b6d4f731cc5ead4372083abf6515c05dc3
Diffstat (limited to 'designateclient/tests/test_exceptions.py')
-rw-r--r--designateclient/tests/test_exceptions.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/designateclient/tests/test_exceptions.py b/designateclient/tests/test_exceptions.py
new file mode 100644
index 0000000..e307e9b
--- /dev/null
+++ b/designateclient/tests/test_exceptions.py
@@ -0,0 +1,56 @@
+# Copyright 2015 Rackspace Inc.
+#
+# Author: James Li <james.li@rackspace.com>
+#
+# 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 designateclient import exceptions
+from designateclient.tests import base
+
+
+class RemoteErrorTestCase(base.TestCase):
+ response_dict = {
+ 'message': None,
+ 'code': 500,
+ 'type': None,
+ 'errors': None,
+ 'request_id': 1234
+ }
+
+ def test_get_error_message(self):
+ expected_msg = 'something wrong'
+ self.response_dict['message'] = expected_msg
+ remote_err = exceptions.RemoteError(**self.response_dict)
+ self.assertEqual(expected_msg, remote_err.message)
+
+ def test_get_error_message_with_errors(self):
+ expected_msg = "u'nodot.com' is not a 'domainname'"
+ errors = {"errors": [
+ {"path": ["name"],
+ "message": expected_msg,
+ "validator": "format",
+ "validator_value": "domainname"}
+ ]
+ }
+ self.response_dict['message'] = None
+ self.response_dict['errors'] = errors
+ remote_err = exceptions.RemoteError(**self.response_dict)
+ self.assertEqual(expected_msg, remote_err.message)
+
+ def test_get_error_message_with_type(self):
+ expected_msg = 'invalid_object'
+ self.response_dict['message'] = None
+ self.response_dict['errors'] = None
+ self.response_dict['type'] = expected_msg
+ remote_err = exceptions.RemoteError(**self.response_dict)
+ self.assertEqual(expected_msg, remote_err.message)