Пример #1
0
def kafka_resource(event_loop):
    kafka_resource = KafkaResource()
    kafka_resource.loop = event_loop

    yield kafka_resource

    event_loop.run_until_complete(kafka_resource.stop())
Пример #2
0
async def test_get_confluent_kafka_settings():
    kafka_resource = KafkaResource()
    settings = mock.MagicMock()
    settings.get = AsyncMock()
    kafka_resource.settings = settings
    settings_response = await kafka_resource.get_confluent_kafka_settings()
    assert isinstance(settings_response, dict)
Пример #3
0
def test_add_inputs_decorator():
    kafka_resource = KafkaResource()

    @KafkaInput(topic="cats", resource=kafka_resource)
    def handle_cats(message):
        pass

    @KafkaInput(topic="dogs", resource=kafka_resource)
    def handle_dogs(message):
        pass

    assert handle_cats in kafka_resource.inputs.values()
    assert handle_dogs in kafka_resource.inputs.values()
Пример #4
0
async def test_consumer_offset_false():
    kafka_resource = KafkaResource(offset_reset=False)
    kafka_resource.settings = AsyncDict()
    kafka_resource.settings["bootstrap_servers"] = "127.0.0.1"
    settings = await kafka_resource.get_confluent_kafka_settings()
    assert "auto.offset.reset" not in settings
Пример #5
0
async def test_connect_to_kafka_invalid_settings():
    kafka_resource = KafkaResource()
    invalid_settings = "jfhf"
    with pytest.raises(Exception):
        await kafka_resource.connect_to_kafka(invalid_settings)
Пример #6
0
def test_add_outputs():
    outputs = [KafkaOutput(topic="cats"), KafkaOutput(topic="dogs")]
    kafka_resource = KafkaResource(outputs=outputs)
    assert [output in outputs for output in kafka_resource.outputs]
Пример #7
0
def test_add_inputs():
    inputs = [KafkaInput(topic="cats"), KafkaInput(topic="dogs")]
    kafka_resource = KafkaResource(inputs=inputs)
    assert [input_value in inputs for input_value in kafka_resource.inputs]
Пример #8
0
def kafka_resource():
    return KafkaResource()