def calvincontrol():
    control = CalvinControl()
    control.send_response = Mock()
    control.send_response = Mock()
    control.node = Mock()
    control.node.quitting = False
    return control
Пример #2
0
def calvincontrol():
    control = CalvinControl()
    control.send_response = Mock()
    control.send_response = Mock()
    control.node = Mock()
    control.node.quitting = False
    return control
Пример #3
0
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_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
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
def calvincontrol():
    control = CalvinControl()
    control.send_response = Mock()
    control.send_response = Mock()
    return control
Пример #9
0
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
Пример #10
0
def calvincontrol():
    control = CalvinControl()
    control.send_response = Mock()
    control.send_response = Mock()
    return control
Пример #11
0
def test_routes_correctly(url, match, handler):
    control = CalvinControl()
    handler = control._handler_for_route(url)
    assert handler is not None