def test_httpexception_message(self): """Make sure the message from a HTTPException is preserved.""" msg = "foo" resp = _exception_to_response(exc.HTTPBadRequest(msg), "cookie") self.assertEqual(json.loads(resp.body)['detail'], msg)
def test_exception_message(self): """Make sure the message from a non-HTTPException is elided.""" msg = "Something went terribly wrong" resp = _exception_to_response(ValueError(msg), "cookie") self.assertNotEqual(json.loads(resp.body)['detail'], msg)
def test_no_traceback(self): """Make sure there is no traceback.""" resp = _exception_to_response(Exception("foo"), "cookie") self.assertFalse('traceback' in json.loads(resp.body))
def test_has_cookie(self): """Make sure the cookie is included.""" resp = _exception_to_response(Exception("foo"), "cookie") body = json.loads(resp.body) self.assertTrue('cookie' in body) self.assertEqual(body['cookie'], 'cookie')
def test_has_detail(self): """Make sure there's error detail.""" resp = _exception_to_response(Exception("foo"), "cookie") body = json.loads(resp.body) self.assertTrue('detail' in body)
def test_status(self): """Make sure webob exception statuses are preserved.""" not_found = exc.HTTPNotFound("Sorry") resp = _exception_to_response(not_found) self.assertEqual(not_found.status, resp.status)
def test_types(self): resp = _exception_to_response(Exception("foo")) self.assertTrue(isinstance(resp, Response))