def test_response_ok(): response = response_ok("text/html", "<html></html>") assert "HTTP/1.1 200 OK" in response[:15] print response head, content = response.split("\r\n\r\n", 1) lines = head.split("\r\n") assert "HTTP/1.1 200 OK" == lines[0] assert "Content-Type" in lines[1] assert "Content-Length" in lines[2]
def test_response_ok(self): """test response ok""" body = b"foo" mimetype = b"image/bmp" response = http_server.response_ok(body=body, mimetype=mimetype) str_response = response.decode() self.assertIn("\r\n\r\n", str_response) str_header, str_body = str_response.split("\r\n\r\n") self.assertEqual(body.decode(), str_body) self.assertEqual("HTTP/1.1 200 OK", str_header.splitlines()[0]) self.assertIn("Content-Type: " + mimetype.decode(), str_header)
def test_response_ok(self): mimetype = b"image/bmp" content = b"foo" response = http_server.response_ok(content=content, mimetype=mimetype) str_response = response.decode() self.assertIn("\r\n\r\n", str_response) str_header, str_content = str_response.split("\r\n\r\n") self.assertEqual(content.decode(), str_content) self.assertEqual("HTTP/1.1 200 OK", str_header.splitlines()[0]) self.assertIn("Content-Type: " + mimetype.decode(), str_header)
def call_function_under_test(self, body="", mimetype="text/plain"): """call the `response_ok` function from our http_server module""" from http_server import response_ok return response_ok(body=body, mimetype=mimetype)
def call_function_under_test(self, body="", mimetype="text/plain"): """call the `response_ok` function from our http_server module""" from http_server import response_ok return response_ok(body=body, mimetype=mimetype)
def call_function_under_test(self): """call the `response_ok` function from our http_server module""" from http_server import response_ok return response_ok()
def call_function_under_test(self): """call the `response_ok` function from our http_server module""" from http_server import response_ok return response_ok()