def kafka_resource(event_loop): kafka_resource = KafkaResource() kafka_resource.loop = event_loop yield kafka_resource event_loop.run_until_complete(kafka_resource.stop())
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)
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()
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
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)
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]
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]
def kafka_resource(): return KafkaResource()