SIENTIAPDE-1110
Update sientia-dataops-library version to 1.2.0 in requirements.txt; refactor logging in activities to use a unified Logger instance and include metadata in log messages across various activities.
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
from logging import Logger
|
||||
from unittest.mock import MagicMock, patch, call
|
||||
import pytest
|
||||
from sientia_do.notifications.handlers import NotificationHandler
|
||||
@@ -22,7 +21,7 @@ def mock_datetime():
|
||||
|
||||
@pytest.fixture
|
||||
def faker_instance(mock_kafka_producer):
|
||||
logger = MagicMock(spec=Logger)
|
||||
logger = MagicMock()
|
||||
notification_handler = MagicMock(spec=NotificationHandler)
|
||||
return Faker(
|
||||
bootstrap_servers='localhost:9092',
|
||||
@@ -37,6 +36,15 @@ async def test_faker_init(faker_instance, mock_kafka_producer):
|
||||
assert faker_instance.producer is not None
|
||||
assert len(faker_instance.tags) == 6
|
||||
|
||||
metadata = {
|
||||
'metadata': {
|
||||
'model_id': 'test_model_id',
|
||||
'model_name': 'test_model',
|
||||
'schedule_name': 'test_schedule',
|
||||
'workflow_name': 'scouter'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_generate_and_send_data_default_count(faker_instance,
|
||||
@@ -56,7 +64,7 @@ async def test_generate_and_send_data_default_count(faker_instance,
|
||||
]
|
||||
|
||||
# Call the method
|
||||
await faker_instance.generate_and_send_data({'topic': 'test_topic'})
|
||||
await faker_instance.generate_and_send_data({'topic': 'test_topic', **metadata})
|
||||
|
||||
# Verify the producer was called 3 times (default count)
|
||||
assert mock_kafka_producer.send.call_count == 3
|
||||
@@ -92,7 +100,8 @@ async def test_generate_and_send_data_custom_count(faker_instance, mock_kafka_pr
|
||||
# Call the method with custom count
|
||||
await faker_instance.generate_and_send_data({
|
||||
'topic': 'test_topic',
|
||||
'num_messages': 2
|
||||
'num_messages': 2,
|
||||
**metadata
|
||||
})
|
||||
|
||||
# Verify the producer was called 2 times
|
||||
@@ -104,7 +113,7 @@ async def test_generate_and_send_data_custom_count(faker_instance, mock_kafka_pr
|
||||
async def test_generate_and_send_data_no_topic(faker_instance):
|
||||
"""Test that ValueError is raised when no topic is provided"""
|
||||
with pytest.raises(ValueError, match="Topic must be specified in input_data"):
|
||||
await faker_instance.generate_and_send_data({})
|
||||
await faker_instance.generate_and_send_data({**metadata})
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -112,7 +121,7 @@ async def test_generate_and_send_data_no_topic(faker_instance):
|
||||
async def test_generate_and_send_data_random_values(_random, faker_instance, mock_kafka_producer):
|
||||
"""Test that random values are within expected ranges"""
|
||||
# Call the method
|
||||
await faker_instance.generate_and_send_data({'topic': 'test_topic'})
|
||||
await faker_instance.generate_and_send_data({'topic': 'test_topic', **metadata})
|
||||
|
||||
# Get the call arguments
|
||||
call_args = mock_kafka_producer.send.call_args[1]['value']
|
||||
@@ -132,7 +141,8 @@ async def test_generate_and_send_data_generate_null_values(
|
||||
mock_kafka_producer):
|
||||
# Call the method
|
||||
await faker_instance.generate_and_send_data({'topic': 'test_topic',
|
||||
'num_messages': 1})
|
||||
'num_messages': 1,
|
||||
**metadata})
|
||||
|
||||
# Get the call arguments
|
||||
call_args = mock_kafka_producer.send.call_args[1]['value']
|
||||
|
||||
Reference in New Issue
Block a user