def calvincontrol(): control = CalvinControl() control.send_response = Mock() control.send_response = Mock() control.node = Mock() control.node.quitting = False return control
def test_routes_correctly(url, match, handler, uuids): control = CalvinControl() handler_func, mo = control._handler_for_route(url.format(**uuids)) assert handler_func is not None assert handler_func.__name__ == handler assert mo is not None if match is not None: # If any of the 'match'es are in uuids we assume they should be uuids match = [uuids.get(m, m) for m in match] assert list(mo.groups()) == match
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
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 calvincontrol(): control = CalvinControl() control.send_response = Mock() control.send_response = Mock() return control
def test_routes_correctly(url, match, handler): control = CalvinControl() handler = control._handler_for_route(url) assert handler is not None