def test_handle_request_range_from_middle(): # setup clientsock = MockClientSocket(recv_data=HTTP_REQUEST_RANGE_FROM_MIDDLE) # run handle_request(clientsock) # assert tools.assert_equals(clientsock.sent_data, HTTP_RESPONSE_RANGE_FROM_MIDDLE)
def test_handle_request_known_file(): #setup clientsock = MockClientSocket(recv_data=HTTP_REQUEST_KNOWN_FILE) #run handle_request(clientsock) # assert tools.assert_equals(clientsock.close_called, True) tools.assert_equals(clientsock.sent_data, HTTP_RESPONSE_KNOWN_FILE)
def test_stream_end_part_of_file(): # setup file = get_file(FILE) range = (10, file.file_size - 1) clientsock = MockClientSocket(recv_data=HTTP_REQUEST_KNOWN_FILE) # run file.stream_to(clientsock, range, file_chunk_size=None) # assert tools.assert_equals(clientsock.sent_data, 'test 1')
def test_simple_response(): #setup response = HttpResponse(protocol='HTTP/1.1', status_code=200) response.headers['Date'] = 'Fri, 31 Dec 1999 23:59:59 GMT' response.headers['Content-type'] = 'text/plain' response.content = 'This is a test' expected_response_msg = \ '''HTTP/1.1 200 OK Date: Fri, 31 Dec 1999 23:59:59 GMT Content-type: text/plain This is a test''' #run clientsock = MockClientSocket() response.write_to(clientsock) #assert tools.assert_equals(clientsock.sent_data, expected_response_msg)