def test_get_index_file_date_header(): """ Checks the existance of the Date header """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /index.html HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) assert b'Date: ' in mock_send_content
def test_get_index_file_content_type_header(): """ Checks the Content-Type header """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /index.html HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) assert b'Content-Type: text/html\r\n' in mock_send_content
def test_get_index_file_connection_header(): """ Checks the Connection header """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /index.html HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) assert b'Connection: close\r\n' in mock_send_content
def test_get_index_file_status_line_missing(): """ Checks the status line when making an unsuccessful request. """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /bad-path-that-should-not-exist HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) assert mock_send_content.startswith(b'HTTP/1.1 404 Not Found\r\n')
def test_get_index_file_status_line_ok(): """ Checks the status line when making a successful request to the index file. """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /index.html HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) assert mock_send_content.startswith(b'HTTP/1.1 200 OK\r\n')
def test_get_index_file_response_content(): """ Checks that the content of the page is returned """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /index.html HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) page_content = get_fixture_content('fixtures/index.html') assert mock_send_content.endswith(page_content)
def test_get_jpg_file(): """ Check that /sebern1.jpg works and parse the full response """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /sebern1.jpg HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) page_content = get_fixture_content('fixtures/sebern1.jpg') check_response(mock_send_content, page_content, 'image/jpeg')
def test_get_gif_file(): """ Check that /e-sebern2.gif works and parse the full response """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /e-sebern2.gif HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) page_content = get_fixture_content('fixtures/e-sebern2.gif') check_response(mock_send_content, page_content, 'image/gif')
def test_get_css_file(): """ Check that /style.css works and parse the full response """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /style.css HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) page_content = get_fixture_content('fixtures/style.css') check_response(mock_send_content, page_content, 'text/css')
def test_get_index_file(): """ Check that /index.html works and parse the full response """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET /index.html HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) page_content = get_fixture_content('fixtures/index.html') check_response(mock_send_content, page_content)
def test_get_root_file(): """ Check that the root URL gets resolved to /index.html and parse the full response """ global mock_recv_content global mock_send_content mock_socket = get_mock_socket() mock_recv_content = b'GET / HTTP/1.1\r\n\r\n' mock_send_content = b'' handle_request(mock_socket) page_content = get_fixture_content('fixtures/index.html') check_response(mock_send_content, page_content)