After running all of the tests, run_test.sh will report any pep8 errors
found in the tree.
+Running individual tests
+
+ Individual tests can be run using run_tests.py, you just need to pass
+ the dot-separated path to the module you want as an argument to it.
+ For example, the following would run only the APITestV11 tests from
+ quantum/tests/unit/test_api.py:
+
+ $ ./run_tests.sh quantum.tests.unit.test_api:APITestV11
+
Adding more tests
Quantum is a pretty new code base at this point and there is plenty of
def fault_body_function_v11(wrapped_exc):
""" This function creates the contents of the body for a fault
- response for Quantum API v1.0.
+ response for Quantum API v1.1.
:param wrapped_exc: Exception thrown by the Quantum service
:type wrapped_exc: quantum.common.exceptions.QuantumException
# @author: Salvatore Orlando, Citrix Systems
import logging
-import unittest
+import unittest2 as unittest
+import mock
+
+from quantum.api.api_common import APIFaultWrapper
+from quantum.api.networks import Controller
from quantum.common.test_lib import test_config
from quantum.common import utils
from quantum.db import api as db
def test_multitenancy_json(self):
self._test_multitenancy('json')
+
+ def test_internal_error(self):
+ """Check that internal errors do not leak.
+
+ Any internal, unexpected error should be turned into a 500 response
+ without any traces of the original exception.
+ """
+ orig_exception_msg = "An exception with a traceback"
+
+ @APIFaultWrapper()
+ def raise_exception(self, *args, **kwargs):
+ raise Exception(orig_exception_msg)
+
+ list_network_req = testlib.network_list_request(self.tenant_id, "json")
+ with mock.patch.object(Controller, 'index', new=raise_exception):
+ list_network_res = list_network_req.get_response(self.api)
+ self.assertEqual(list_network_res.status_int, 500)
+ self.assertNotIn(orig_exception_msg, list_network_res.body)
action_result = Fault(ex,
self._xmlns,
self._fault_body_function)
+ except Exception:
+ LOG.exception("Internal error")
+ # Do not include the traceback to avoid returning it to clients.
+ action_result = Fault(webob.exc.HTTPServerError(),
+ self._xmlns,
+ self._fault_body_function)
if isinstance(action_result, dict) or action_result is None:
response = self.serializer.serialize(action_result,