def test_http_response(self): web.ctx.headers = [] http_codes = ( (200, 'ok'), (201, 'created'), (202, 'accepted'), (204, 'no content'), (400, 'bad request :('), (401, 'unauthorized'), (403, 'forbidden'), (404, 'not found, try again'), (405, 'no method'), (406, 'unacceptable'), (409, 'ooops, conflict'), (415, 'unsupported media type'), (500, 'internal problems'), ) headers = { 'Content-Type': 'application/json', 'ETag': '737060cd8c284d8af7ad3082f209582d', } # test response status code and message for code, message in http_codes: with self.assertRaises(web.HTTPError) as cm: raise BaseHandler.http(code, message, headers) self.assertTrue(web.ctx.status.startswith(str(code))) self.assertTrue(cm.exception.data, message) for header, value in headers.items(): self.assertIn((header, value), web.ctx.headers)
def test_http_response(self): web.ctx.headers = [] http_codes = ( (200, 'ok'), (201, 'created'), (202, 'accepted'), (204, 'no content'), (400, 'bad request :('), (401, 'unauthorized'), (403, 'forbidden'), (404, 'not found, try again'), (405, 'no method'), (406, 'unacceptable'), (409, 'ooops, conflict'), (415, 'unsupported media type'), (500, 'internal problems'), ) headers = { 'Content-Type': 'application/json', 'ETag': '737060cd8c284d8af7ad3082f209582d', } # test response status code and message for code, message in http_codes: with self.assertRaises(web.HTTPError) as cm: raise BaseHandler.http( status_code=code, msg=message, headers=headers ) self.assertTrue(web.ctx.status.startswith(str(code))) self.assertTrue(cm.exception.data, message) for header, value in headers.items(): self.assertIn((header, value), web.ctx.headers)
def GET(self_inner): web.header('Content-Type', 'text/plain') return BaseHandler.get_requested_mime()
def GET(self_inner): web.header('Content-Type', 'application/json') data = BaseHandler.get_param_as_set('test_param', delimiter=';') return json.dumps(list(data))