Example #1
0
def test_instantiate_link_and_connect_to_broker(mockstomp):
    """Test the Stomp connection routine."""
    stomp = StompTransport()
    mockconn = mockstomp.Connection.return_value

    assert not stomp.is_connected()

    stomp.connect()

    mockstomp.Connection.assert_called_once()
    mockconn.connect.assert_called_once()
    assert stomp.is_connected()

    stomp.connect()

    mockstomp.Connection.assert_called_once()
    mockconn.connect.assert_called_once()
    assert stomp.is_connected()

    stomp.disconnect()

    mockstomp.Connection.assert_called_once()
    mockconn.connect.assert_called_once()
    mockconn.disconnect.assert_called_once()
    assert not stomp.is_connected()

    stomp.disconnect()

    mockstomp.Connection.assert_called_once()
    mockconn.connect.assert_called_once()
    mockconn.disconnect.assert_called_once()
    assert not stomp.is_connected()
Example #2
0
def test_error_handling_on_broadcast(mockstomp):
    """Unrecoverable errors during broadcasting should mark the connection as disconnected."""
    stomp = StompTransport()
    stomp.connect()
    mockconn = mockstomp.Connection.return_value
    mockconn.send.side_effect = stomppy.exception.NotConnectedException()
    mockstomp.exception = stomppy.exception

    with pytest.raises(workflows.Disconnected):
        stomp._broadcast(str(mock.sentinel.channel), mock.sentinel.message)
    assert not stomp.is_connected()
Example #3
0
def test_error_handling_when_connecting_to_broker(mockstomp):
    """Test the Stomp connection routine."""
    stomp = StompTransport()
    mockconn = mockstomp.Connection.return_value
    mockconn.connect.side_effect = stomppy.exception.ConnectFailedException()
    mockstomp.exception.ConnectFailedException = (
        stomppy.exception.ConnectFailedException)

    with pytest.raises(workflows.Disconnected):
        stomp.connect()

    assert not stomp.is_connected()