def test_send_response(): control = CalvinControl() control.tunnel_client = Mock() handle = Mock() connection = Mock() data = {'value': 1} status = 200 control.connections[handle] = connection control.send_response(handle, None, data, status) assert control.tunnel_client.send.called control.connections[handle] = connection connection.connection_lost = True control.send_response(handle, connection, data, status) assert not connection.send.called control.connections[handle] = connection connection.connection_lost = False control.send_response(handle, connection, data, status) assert connection.send.called connection.send.assert_called_with(data) assert handle not in control.connections
def test_send_streamhader(): control = CalvinControl() control.tunnel_client = Mock() handle = Mock() connection = Mock() control.connections[handle] = connection control.send_streamheader(handle, None) assert control.tunnel_client.send.called control.connections[handle] = connection connection.connection_lost = True control.send_streamheader(handle, connection) assert not connection.send.called control.connections[handle] = connection connection.connection_lost = False control.send_streamheader(handle, connection) assert connection.send.called