def test_generate_response_with_png_mime_type_and_bytes_body(): request = Request('GET', '/random/Screenshot_20161222-082602.png', None, None, None) expected_result = b'HTTP/1.1 200 OK\r\nContent-Type: image/png\r\nContent-Length: 62995\r\n\r\n\x89PN' assert generate_response(request, 'tests/webroot')[:70] == expected_result
def test_sends_redirect_response_if_dir_without_end_slash(): request = Request('GET', '/cat_pics', None, None, None) expected_result = b'HTTP/1.1 301 Moved Permanently\r\nContent-Length: 0\r\nLocation: /cat_pics/\r\n\r\n' assert generate_response(request, 'tests/webroot') == expected_result
def test_generate_response_for_HEAD_request_of_root_dir(): request = Request('HEAD', '/', None, None, None) expected_result = b'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 201\r\n\r\n' assert generate_response(request, 'tests/webroot') == expected_result
def test_generate_response_for_PUT_request(): request = Request('PUT', '/', None, None, None) expected_result = b'HTTP/1.1 501 Not Implemented\r\n\r\n' assert generate_response(request, 'tests/webroot') == expected_result
def test_generate_response_for_HEAD_request_of_a_text_file(): request = Request('HEAD', '/lorem_ipsum.txt', None, None, None) expected_result = b'HTTP/1.1 200 OK\r\n' \ b'Content-Type: text/plain\r\n' \ b'Content-Length: 362\r\n\r\n' assert generate_response(request, 'tests/webroot') == expected_result
def test_generate_response_for_GET_request(): request = Request('GET', '/', None, None, None) expected_result = b'HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: 201\r\n\r\n<h1>/</h1><table><tbody><tr><td><a href="cat_pics">cat_pics/</a></td></tr><tr><td><a href="random">random/</a></td></tr><tr><td><a href="lorem_ipsum.txt">lorem_ipsum.txt</a></td></tr></tbody></table>\r\n' assert generate_response(request, 'tests/webroot') == expected_result