diff options
| author | Chris Yeoh <cyeoh@au1.ibm.com> | 2013-05-22 13:35:31 +0930 |
|---|---|---|
| committer | Chris Yeoh <cyeoh@au1.ibm.com> | 2013-06-19 14:56:17 +0930 |
| commit | 7ff01fda2a307eb75baf7010ac6374197c5fa880 (patch) | |
| tree | be7bb915f5d04897b8d5edd4df850dd5ec345865 /nova/tests | |
| parent | 2bcd6b59a6d6848144ff9fb4f7b4c2241b907515 (diff) | |
Adds expected_errors decorator for API v3
Adds an expected_errors decorator for v3 API methods which allows
the specification of what exceptions can be raised within the
method. If an unexpected error occurs a 500 is instead returned
which plus a request to file a bug report
Partially implements blueprint v3-api-expected-errors
Change-Id: I5723e576b30b47744394517cdb1ff6bab1d8f78b
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/test_v3_extensions.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/nova/tests/api/openstack/compute/test_v3_extensions.py b/nova/tests/api/openstack/compute/test_v3_extensions.py index 97429ca45..ec472f38a 100644 --- a/nova/tests/api/openstack/compute/test_v3_extensions.py +++ b/nova/tests/api/openstack/compute/test_v3_extensions.py @@ -16,10 +16,12 @@ from oslo.config import cfg import stevedore +import webob.exc from nova.api import openstack from nova.api.openstack import compute from nova.api.openstack.compute import plugins +from nova.api.openstack import extensions from nova import exception from nova import test @@ -139,3 +141,38 @@ class ExtensionLoadingTestCase(test.TestCase): self.stubs.Set(plugins, 'LoadedExtensionInfo', fake_loaded_extension_info) self.assertRaises(exception.CoreAPIMissing, compute.APIRouterV3) + + def test_extensions_expected_error(self): + @extensions.expected_errors(404) + def fake_func(): + raise webob.exc.HTTPNotFound() + + self.assertRaises(webob.exc.HTTPNotFound, fake_func) + + def test_extensions_expected_error_from_list(self): + @extensions.expected_errors((404, 403)) + def fake_func(): + raise webob.exc.HTTPNotFound() + + self.assertRaises(webob.exc.HTTPNotFound, fake_func) + + def test_extensions_unexpected_error(self): + @extensions.expected_errors(404) + def fake_func(): + raise webob.exc.HTTPConflict() + + self.assertRaises(webob.exc.HTTPInternalServerError, fake_func) + + def test_extensions_unexpected_error_from_list(self): + @extensions.expected_errors((404, 413)) + def fake_func(): + raise webob.exc.HTTPConflict() + + self.assertRaises(webob.exc.HTTPInternalServerError, fake_func) + + def test_extensions_unexpected_policy_not_authorized_error(self): + @extensions.expected_errors(404) + def fake_func(): + raise exception.PolicyNotAuthorized(action="foo") + + self.assertRaises(exception.PolicyNotAuthorized, fake_func) |
