SIENTIAPDE-1005

Unit test fixes
This commit is contained in:
vitor-aignosi
2025-05-19 15:52:39 -03:00
parent 03d62cb5f9
commit cefb5e48ff
4 changed files with 17 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ from scouter.activities.postgres import Postgres
from scouter.activities.redis import Redis from scouter.activities.redis import Redis
from scouter.activities.kafka import Kafka from scouter.activities.kafka import Kafka
from scouter.activities.gates import Gates from scouter.activities.gates import Gates
from pytest import mark
@patch('scouter.activities.activities.Postgres.__init__') @patch('scouter.activities.activities.Postgres.__init__')
@@ -91,11 +92,12 @@ def test___init__(mock_gates_init, mock_kafka_init, mock_redis_init, mock_postgr
) )
@mark.asyncio
@patch('scouter.activities.activities.Postgres.__init__') @patch('scouter.activities.activities.Postgres.__init__')
@patch('scouter.activities.activities.Redis.__init__') @patch('scouter.activities.activities.Redis.__init__')
@patch('scouter.activities.activities.Kafka.__init__') @patch('scouter.activities.activities.Kafka.__init__')
def test_prepare_activity(_mock_kafka_init, async def test_prepare_activity(_mock_kafka_init,
_mock_redis_init, _mock_postgres_init): _mock_redis_init, _mock_postgres_init):
postgres_config = { postgres_config = {
'host': 'localhost', 'host': 'localhost',
'port': 5432, 'port': 5432,
@@ -137,7 +139,7 @@ def test_prepare_activity(_mock_kafka_init,
'model_id': 'test-model-id' 'model_id': 'test-model-id'
} }
activities.prepare_activity(input_data) await activities.prepare_activity(input_data)
assert activities.notification_handler.base_notification.pipeline_name == input_data[ assert activities.notification_handler.base_notification.pipeline_name == input_data[
'workflow_name'] 'workflow_name']

View File

@@ -1,5 +1,5 @@
from unittest.mock import MagicMock from unittest.mock import MagicMock
from pytest import fixture from pytest import fixture, mark
from sientia_do.notifications.models import Notification from sientia_do.notifications.models import Notification
from scouter.activities.base import BaseActivity from scouter.activities.base import BaseActivity
@@ -12,7 +12,8 @@ def base_activity():
) )
def test_prepare_activity(base_activity): @mark.asyncio
async def test_prepare_activity(base_activity):
base_activity.notification_handler.base_notification = Notification( base_activity.notification_handler.base_notification = Notification(
project="project", project="project",
pipeline="pipeline", pipeline="pipeline",
@@ -21,7 +22,7 @@ def test_prepare_activity(base_activity):
model_id="-", model_id="-",
) )
base_activity.prepare_activity( await base_activity.prepare_activity(
{ {
'workflow_name': 'test_workflow', 'workflow_name': 'test_workflow',
'schedule_name': 'test_schedule', 'schedule_name': 'test_schedule',

View File

@@ -108,7 +108,8 @@ async def test_generate_and_send_data_no_topic(faker_instance):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_generate_and_send_data_random_values(faker_instance, mock_kafka_producer): @patch('scouter.activities.faker.random.random', return_value=0.5)
async def test_generate_and_send_data_random_values(_random, faker_instance, mock_kafka_producer):
"""Test that random values are within expected ranges""" """Test that random values are within expected ranges"""
# Call the method # Call the method
await faker_instance.generate_and_send_data({'topic': 'test_topic'}) await faker_instance.generate_and_send_data({'topic': 'test_topic'})

View File

@@ -30,7 +30,9 @@ async def test_scouter_workflow(mock_workflow, scouter):
'schedule_name': 'test_schedule', 'schedule_name': 'test_schedule',
'model_name': 'test_model', 'model_name': 'test_model',
'model_id': 'test_model_id' 'model_id': 'test_model_id'
} },
retry_policy=ANY,
start_to_close_timeout=ANY
) )
mock_workflow.execute_activity_method.assert_called_once_with( mock_workflow.execute_activity_method.assert_called_once_with(
@@ -75,7 +77,9 @@ async def test_scouter_workflow_empty(mock_workflow, scouter):
'schedule_name': 'test_schedule', 'schedule_name': 'test_schedule',
'model_name': 'test_model', 'model_name': 'test_model',
'model_id': 'test_model_id' 'model_id': 'test_model_id'
} },
retry_policy=ANY,
start_to_close_timeout=ANY
) )
mock_workflow.execute_activity_method.assert_called_once_with( mock_workflow.execute_activity_method.assert_called_once_with(