"""Product logging adapter.""" from kafka_utils.consumer.source.msk import MSKMessage from owslogger import logger from content_utils.logging.product_logging import ProductEventLogger mock_logger = logger.setup('test', 'test_logger', 'INFO', 'content_utils', 1.0) def test_product_logger_no_event(): """Test running the logger with no event.""" test_logger = ProductEventLogger(mock_logger) test_logger.start() test_logger.set_data(status='foo', result='bar') test_logger.end() assert test_logger.data == { 'status': 'foo', 'result': 'bar', 'event_key': '', 'product_id': '', 'message': 'foo: result="bar"', 'operation': '', 'queue_id': '' } def test_product_logger_event(mock_avro_serializer): """Test running the logger with an event.""" test_logger = ProductEventLogger(mock_logger) event = MSKMessage({ 'topic': 'foo', 'key': None, 'value': b'AAAAABwAAgL0pZiH3mCI3LQDDgACSG93cy1wcm9kdWN0LXJldmlldy1pbnRlZ3JhdGlvbi10ZXN0cwAA' }) test_logger.start(event, 'foo-1', mock_avro_serializer) test_logger.end() assert test_logger.data == { 'status': 'error', 'result': '', 'event_key': 'foo-1', 'product_id': 3577604, 'message': 'error: product_id=3577604 queue_id=7 event_key=foo-1', 'operation': 'create:approve', 'queue_id': 7 }