class MangleResponseTest(unittest.TestCase): """Make sure _mangle_response works.""" def setUp(self): self.app = App(debug=True) def test_exceptions(self): """Make sure exceptions are handled properly.""" exc = ValueError("Expected some cheese.") resp = self.app._mangle_response(Request(_env()), exc) body = json.loads(resp.body) self.assertTrue(body['detail'].startswith('Caught exception ' + str(type(exc)))) def test_traceback_list(self): """Make sure tracebacks are included when they're lists.""" ex = Exception("foo") ex.__traceback__ = traceback.extract_stack() resp = _debug_exception_to_reponse(Request(_env()), ex) body = json.loads(resp.body) self.assertTrue('traceback' in body) self.assertNotEqual(body['traceback'], ["No traceback available."]) def test_nonerror_exceptions(self): """Non-error exceptions shouldn't get mangled a traceback.""" ex = exc.HTTPMovedPermanently(headers={'Location': "/foo.json"}) resp = self.app._mangle_response(Request(_env()), ex) self.assertTrue(resp is ex) def test_server_error_exceptions(self): """Non-error exceptions shouldn't get mangled a traceback.""" ex = exc.HTTPInternalServerError() resp = self.app._mangle_response(Request(_env()), ex) self.assertTrue(resp is not ex) def test_client_error_exceptions(self): """Non-error exceptions shouldn't get mangled a traceback.""" ex = exc.HTTPBadRequest() resp = self.app._mangle_response(Request(_env()), ex) self.assertTrue(resp is not ex)
class MangleResponseTest(unittest.TestCase): """Make sure _mangle_response works.""" def setUp(self): self.app = App(debug=True) def test_exceptions(self): """Make sure exceptions are handled properly.""" exc = ValueError("Expected some cheese.") resp = self.app._mangle_response(exc) body = json.loads(resp.body) self.assertTrue(body['detail'].startswith('Caught exception ' + str(type(exc))))
def test_nondebug_exceptions(self): """Make sure exceptions are handled properly based on debug.""" app = App(debug=False) resp = app._mangle_response( Request(_env()), exc.HTTPInternalServerError("Whops")) self.assertFalse('traceback' in json.loads(resp.body))
def test_debug_exceptions(self): """Make sure exceptions are handled properly based on debug.""" app = App(debug=True) resp = app._mangle_response(exc.HTTPBadRequest("Whops")) self.assertTrue('traceback' in json.loads(resp.body))