Exemplo n.º 1
0
def test_subscribe(monkeypatch):
    # Test subscription and message receipt
    mock_connection(monkeypatch, connection_success=True)

    # connection, exchange, queue, key, msg
    def on_message(self, exchange, queue, key, body):
        assert (key == "mykey")
        assert (body == "mybody")

    connection = AsyncConnection(connection_params)
    connection.connect()
    queue = {"exchange": "exchange", "name": "name", "key": "key"}
    connection.subscribe([queue, queue], on_message)
    connection.publish(queue, "key", "mybody")
    assert (consumed_message == "mybody")

    # connection, exchange, queue, key, msg
    def on_message_fail(self, exchange, queue, key, body):
        raise Exception

    connection.subscribe([queue, queue], on_message_fail)
    connection.publish(queue, "key", "mybody")
    assert (consumed_message == "mybody")

    connection.disconnect()
Exemplo n.º 2
0
def test_connect_callback_failure(monkeypatch):
    # Test if connect does not call callback on failure
    mock_connection(monkeypatch, connection_success=False)
    global on_connect_called

    connection = AsyncConnection(connection_params)
    assert (not on_connect_called)
    connection.connect(on_connect)
    assert (not on_connect_called)
Exemplo n.º 3
0
def test_publish(monkeypatch):
    # Test publish message
    mock_connection(monkeypatch, connection_success=True)

    connection = AsyncConnection(connection_params)
    connection.connect()
    queue = {"exchange": "exchange", "name": "name", "key": "key"}
    connection.publish(queue, "key", "message")
    assert (published_message == json.dumps("message"))
    connection.disconnect()
Exemplo n.º 4
0
def test_connect_callback_success(monkeypatch):
    # Test if connect calls callback on success
    mock_connection(monkeypatch, connection_success=True)
    global on_connect_called

    assert (not on_connect_called)
    connection = AsyncConnection(connection_params)
    connection.connect(on_connect)
    assert (on_connect_called)
    connection.disconnect()
Exemplo n.º 5
0
def test_connect_success(monkeypatch):
    # Test if connect reports connection success
    mock_connection(monkeypatch, connection_success=True)

    connection = AsyncConnection(connection_params)
    assert (connection.connect() is True)
    connection.disconnect()
Exemplo n.º 6
0
def test_connect_failure(monkeypatch):
    # Test if connect reports failure to connect
    mock_connection(monkeypatch, connection_success=False)

    connection = AsyncConnection(connection_params)
    assert (connection.connect() is False)