Exemplo n.º 1
0
def test_check_fails_on_getting_channel(connection_init):
    connection = Mock()
    connection_init.return_value = connection
    connection.channel.side_effect = Exception("Failed to get channel")
    destination = DestinationRabbitmq()
    status = destination.check(logger=Mock(), config=config)
    assert status.status == Status.FAILED
Exemplo n.º 2
0
def test_check_succeeds(connection_init):
    result = Mock()
    result.method = Queue.DeclareOk()
    channel = _init_mocks(connection_init=connection_init)
    channel.queue_declare.return_value = result
    destination = DestinationRabbitmq()
    status = destination.check(logger=Mock(), config=config)
    assert status.status == Status.SUCCEEDED
Exemplo n.º 3
0
def test_write():
    f = open("secrets/config.json", )
    config = json.load(f)
    messages = [_record(), _state()]
    destination = DestinationRabbitmq()
    for m in destination.write(config=config,
                               configured_catalog=_configured_catalog(),
                               input_messages=messages):
        assert m.type == Type.STATE
    consume(config)
Exemplo n.º 4
0
def test_write_skips_message_from_unknown_stream(connection_init):
    stream = "shapes"
    data = {"name": "Rectangle", "color": "blue"}
    channel = _init_mocks(connection_init=connection_init)
    input_messages = [_record(stream=stream, data=data), _state()]
    destination = DestinationRabbitmq()
    for m in destination.write(config=config,
                               configured_catalog=_configured_catalog(),
                               input_messages=input_messages):
        assert m.type == Type.STATE
    channel.basic_publish.assert_not_called()
Exemplo n.º 5
0
def test_write_succeeds_with_direct_exchange(connection_init):
    stream = "people"
    data = {"name": "John Doe", "email": "*****@*****.**"}
    channel = _init_mocks(connection_init=connection_init)
    input_messages = [_record(stream=stream, data=data), _state()]
    custom_config = dict(config)
    del custom_config["exchange"]
    destination = DestinationRabbitmq()
    for m in destination.write(config=custom_config,
                               configured_catalog=_configured_catalog(),
                               input_messages=input_messages):
        assert m.type == Type.STATE
    _, _, args = channel.basic_publish.mock_calls[0]
    assert args["exchange"] == ""
    assert json.loads(args["body"]) == data
Exemplo n.º 6
0
def test_write_succeeds(connection_init):
    stream = "people"
    data = {"name": "John Doe", "email": "*****@*****.**"}
    channel = _init_mocks(connection_init=connection_init)
    input_messages = [_record(stream=stream, data=data), _state()]
    destination = DestinationRabbitmq()
    for m in destination.write(config=config,
                               configured_catalog=_configured_catalog(),
                               input_messages=input_messages):
        assert m.type == Type.STATE
    _, _, args = channel.basic_publish.mock_calls[0]
    assert args["exchange"] == "test_exchange"
    assert args["routing_key"] == "test_routing_key"
    assert args["properties"].content_type == "application/json"
    assert args["properties"].headers["stream"] == stream
    assert json.loads(args["body"]) == data
Exemplo n.º 7
0
def test_check_fails_on_creating_connection(connection_init):
    connection_init.side_effect = Exception("Could not open connection")
    destination = DestinationRabbitmq()
    status = destination.check(logger=Mock(), config=config)
    assert status.status == Status.FAILED
Exemplo n.º 8
0
def test_check_succeeds():
    f = open("secrets/config.json", )
    config = json.load(f)
    destination = DestinationRabbitmq()
    status = destination.check(logger=Mock(), config=config)
    assert status.status == Status.SUCCEEDED
Exemplo n.º 9
0
def test_check_fails():
    f = open("integration_tests/invalid_config.json", )
    config = json.load(f)
    destination = DestinationRabbitmq()
    status = destination.check(logger=Mock(), config=config)
    assert status.status == Status.FAILED