Example #1
0
def test_consumer_handle_event():
    config = Config(kafka_bootstrap='localhost:9002',
                    kafka_topic='checks',
                    kafka_ca_path='./',
                    kafka_key_path='./',
                    kafka_cert_path='./',
                    postgres_uri='postgres://*****:*****@localhost:port/db')

    check = Check(response_time=100, status_code=201, url='http://google.com')

    event = Mock()
    event.value = check.serialize()

    kafka_consumer = [event]
    db = Mock()
    cursor = Mock()
    db.cursor = Mock(return_value=cursor)

    consumer = Consumer(config, kafka_consumer, db)  # type: ignore

    consumer.run()

    cursor.execute.assert_called()
Example #2
0
 def send_check_event(self, event: Check):
     self.producer.send(self.topic, event.serialize())
Example #3
0
def test_check_serialize():
    check = Check(response_time=100, status_code=201, url='http://google.com')
    assert check.serialize(
    ) == b'{"response_time": 100, "status_code": 201, "url": "http://google.com"}'