I am new to Python and trying to write a unit test which involves Kafka. I have a class with a function which calls another function to initialize Kafka Producer and then call producer.send(). I want to mock Kafka Producer for my unit test.
Below is my code and I want to write unit test for produce_kafka_message method.
class KafkaProducerIntface
def __init__(self, topic, .....)
self.bootstrap_server = bootstrap_server
self.producer = None
self.post_topic = topic
....
def produce_kafka_message(self, key, value, headers)
self.__initialize_producer__(retries=3)
future = self.producer.send(self.topic, key=key, value=value, headers=headers)
self.producer.flush()
def __initialize_producer__(self, retries=3)
self.producer = KafkaProducer(bootstrap_servers=self.bootstrap_server, acks='all', retries=retries)