diff --git a/tests/activities/test_activities.py b/tests/activities/test_activities.py index 49d555f..bef9e91 100644 --- a/tests/activities/test_activities.py +++ b/tests/activities/test_activities.py @@ -1,10 +1,10 @@ from unittest.mock import patch, MagicMock, ANY +from pytest import mark +from sientia_do.temporal.activities.postgres import Postgres from scouter.activities.activities import Activities -from scouter.activities.postgres import Postgres from scouter.activities.redis import Redis from scouter.activities.kafka import Kafka from scouter.activities.gates import Gates -from pytest import mark @patch('scouter.activities.activities.Postgres.__init__') diff --git a/tests/activities/test_base.py b/tests/activities/test_base.py deleted file mode 100644 index 02e50fc..0000000 --- a/tests/activities/test_base.py +++ /dev/null @@ -1,37 +0,0 @@ -from unittest.mock import MagicMock -from pytest import fixture, mark -from sientia_do.notifications.models import Notification -from scouter.activities.base import BaseActivity - - -@fixture -def base_activity(): - return BaseActivity( - logger=MagicMock(), - notification_handler=MagicMock(), - ) - - -@mark.asyncio -async def test_prepare_activity(base_activity): - base_activity.notification_handler.base_notification = Notification( - project="project", - pipeline="pipeline", - trigger="-", - model_name="-", - model_id="-", - ) - - await base_activity.prepare_activity( - { - 'workflow_name': 'test_workflow', - 'schedule_name': 'test_schedule', - 'model_name': 'test_model', - 'model_id': 'test_model_id', - } - ) - - assert base_activity.notification_handler.base_notification.schedule_name == "test_schedule" - assert base_activity.notification_handler.base_notification.model_name == "test_model" - assert base_activity.notification_handler.base_notification.model_id == "test_model_id" - assert base_activity.notification_handler.base_notification.pipeline_name == "test_workflow" diff --git a/tests/activities/test_postgres.py b/tests/activities/test_postgres.py deleted file mode 100644 index fac1120..0000000 --- a/tests/activities/test_postgres.py +++ /dev/null @@ -1,90 +0,0 @@ -from unittest.mock import ANY, MagicMock, patch -from pytest import fixture -from pytest import mark -from sientia_do.notifications.models import NotificationLevel - -from scouter.activities.postgres import Postgres - - -@fixture -@patch("scouter.activities.postgres.create_engine") -@patch("scouter.activities.postgres.sessionmaker") -def postgres_client(mock_sessionmaker, mock_engine): - # Create a mock session - mock_session = MagicMock() - mock_session.commit = MagicMock() - mock_session.close = MagicMock() - - # Configure the session to work with context management - mock_session.__enter__ = MagicMock(return_value=mock_session) - mock_session.__exit__ = MagicMock(return_value=None) - - # Configure the sessionmaker to return our mock session - mock_sessionmaker.return_value = mock_session - - # Configure the engine to return our mock sessionmaker - mock_engine.return_value = MagicMock() - mock_engine.return_value.dispose = MagicMock() - - # Create the Postgres client - client = Postgres( - host="localhost", - port=5432, - user="postgres", - password="postgres", - dbname="postgres", - min_connections=1, - max_connections=10, - logger=MagicMock(), - notification_handler=MagicMock(), - ) - - # Set up the session factory - client.session_factory = mock_sessionmaker - - return client - - -@mark.asyncio -@patch("scouter.activities.postgres.DataFrame") -async def test_export_data_to_postgres_success(mock_dataframe, postgres_client): - data = {"schema": "test", "table_name": "test", - "data": {"a": [1, 2, 3], "b": [4, 5, 6]}} - await postgres_client.export_data_to_postgres(data) - - # Verify notification handler wasn't called - postgres_client.notification_handler.build_and_send_notification.assert_not_called() - - # Verify session handling - mock_dataframe.assert_called_once_with(data["data"]) - mock_dataframe.return_value.to_sql.assert_called_once_with( - data["table_name"], - postgres_client.engine, - schema=data["schema"], - if_exists="append", - index=False - ) - postgres_client.session_factory.return_value.commit.assert_called_once() - postgres_client.session_factory.return_value.close.assert_called_once() - - -@mark.asyncio -@patch("scouter.activities.postgres.DataFrame", return_value=MagicMock( - to_sql=MagicMock(side_effect=Exception("Error exporting data to postgres")) -)) -async def test_export_data_to_postgres_error(_mock_dataframe, postgres_client): - data = {"schema": "test", "table_name": "test", - "data": {"a": [1, 2, 3], "b": [4, 5, 6]}} - await postgres_client.export_data_to_postgres(data) - - # Verify error notification was sent - postgres_client.notification_handler.build_and_send_notification.assert_called_once_with( - notification_id="ERROR_EXPORTING_DATA_TO_POSTGRES", - message="Error exporting data to postgres: Error exporting data to postgres", - block="export_data_to_postgres", - level=NotificationLevel.ERROR, - attachment_content=ANY - ) - - # Verify session handling - postgres_client.session_factory.return_value.close.assert_called_once() diff --git a/tests/utils/test_logger.py b/tests/utils/test_logger.py deleted file mode 100644 index b931714..0000000 --- a/tests/utils/test_logger.py +++ /dev/null @@ -1,37 +0,0 @@ -import os -from unittest.mock import patch -import logging -import pytest -from scouter.utils.logger import get_logger - - -@pytest.fixture -def mock_env_vars(): - with patch.dict(os.environ, {}, clear=True): - yield - - -@pytest.mark.usefixtures("mock_env_vars") -@patch('scouter.utils.logger.logging.Formatter') -@patch('scouter.utils.logger.logging.StreamHandler') -def test_get_logger_defaults(mock_stream_handler, mock_formatter): - """Test logger creation with default settings""" - # Mock the StreamHandler and Formatter - - logger = get_logger('test_logger') - - # Verify logger settings - assert logger.name == 'test_logger' - assert logger.level == logging.INFO - - # Verify handler configuration - mock_stream_handler.return_value.setLevel.assert_called_once_with('INFO') - mock_stream_handler.return_value.setFormatter.assert_called_once() - - # Verify formatter configuration - mock_formatter.assert_called_once_with( - '%(asctime)s - %(name)s - %(levelname)s - %(message)s' - ) - - # Verify handler was added to logger - assert len(logger.handlers) == 1