Beispiel #1
0
def test_update_empties_send_buffer_after_sending_whole_response():
    connection = Connection(ADDR, fake_socket, Mock())
    response = b'test'
    connection.send(response)
    connection.update()

    assert not connection.send_buffer
Beispiel #2
0
def test_update_sends_whole_response_to_client():
    connection = Connection(ADDR, fake_socket, Mock())
    response = b'test'
    connection.send(response)
    connection.update()

    assert fake_socket.recv_buffer == response
Beispiel #3
0
def test_connection_is_closed_after_the_whole_response_is_sent():
    close_callback = Mock()
    connection = Connection(ADDR, fake_socket, close_callback)
    response = b'test'
    connection.send(response)
    connection.update()

    close_callback.assert_called_with(connection.socket)
Beispiel #4
0
def test_update_called_twice_sends_the_whole_response():
    connection = Connection(ADDR, fake_socket, Mock())
    response = b'testing'
    connection.send(response)
    connection.update()
    connection.update()

    assert connection.send_buffer == b''
    assert fake_socket.recv_buffer == b'testing'
Beispiel #5
0
def test_update_removes_beginning_of_response_from_send_buffer_with_longer_response(
):
    connection = Connection(ADDR, fake_socket, Mock())
    response = b'test longer response'
    connection.send(response)
    connection.update()

    assert connection.send_buffer == b' longer response'
    assert fake_socket.recv_buffer == b'test'
Beispiel #6
0
def test_cannot_send_after_connection_is_closed():
    connection = Connection(ADDR, fake_socket, Mock())
    connection.close()
    with pytest.raises(Exception, match='Connection closed'):
        connection.send(b'')
Beispiel #7
0
def test_send_changes_connection_state_as_sending_response():
    connection = Connection(ADDR, fake_socket, Mock())
    response = b'test'
    connection.send(response)

    assert connection.state == Connection.SENDING_RESPONSE
Beispiel #8
0
def test_send_stores_response_to_send_buffer():
    connection = Connection(ADDR, fake_socket, Mock())
    response = b'test'
    connection.send(response)

    assert connection.send_buffer == response