class RenderTest(unittest.TestCase): def setUp(self): self.app = App() def test_httpexception(self): ex = exc.HTTPNotFound(detail="test") out = self.app._render({}, (Request(_env()), ex)) self.assertTrue(out[0].startswith('404')) def test_non_httpexception(self): ex = ValueError("WTF") out = self.app._render({}, (Request(_env()), ex)) self.assertTrue(out[0].startswith("500")) def test_json_type(self): ex = ValueError("WTF") out = self.app._render({}, (Request(_env()), ex)) headers = dict(out[1]) self.assertTrue('Content-Type' in headers) self.assertEqual(headers['Content-Type'], 'application/json') def test_bad_response(self): resp = self.app._render({}, (Request(_env()), "foo")) self.assertTrue(isinstance(resp, tuple)) self.assertTrue(resp[0].startswith("500")) def test_bad_request(self): message = "You dun goof'd" ex = exc.HTTPBadRequest(message) (response, headers, body) = self.app._render({}, (Request(_env()), ex)) body = "".join(body) self.assertTrue(len(body) > 0) blab = json.loads(body) self.assertEqual(blab['detail'], message)
class RenderTest(unittest.TestCase): def setUp(self): self.app = App() def test_httpexception(self): ex = exc.HTTPNotFound(detail="test") out = self.app._render({}, ex) print out self.assertTrue(out[0].startswith('404')) def test_non_httpexception(self): ex = ValueError("WTF") out = self.app._render({}, ex) self.assertTrue(out[0].startswith("500")) def test_json_type(self): ex = ValueError("WTF") out = self.app._render({}, ex) headers = dict(out[1]) self.assertTrue('Content-Type' in headers) self.assertEqual(headers['Content-Type'], 'application/json') def test_bad_response(self): resp = self.app._render({}, "foo") self.assertTrue(isinstance(resp, tuple)) self.assertTrue(resp[0].startswith("500"))