SIENTIAPDE-1646
Update project configuration and dependencies - Added .mypy_cache and .cursor to .gitignore. - Changed asyncio_default_fixture_loop_scope and asyncio_default_test_loop_scope to "session" in pyproject.toml. - Updated e2e testing dependencies in requirements-dev.txt, replacing fakeredis and mongomock with pytest-httpserver. - Updated requirements.txt to use sientia_do instead of a specific git commit. - Modified sonar-project.properties to remove a file from coverage exclusions. - Enhanced E2E test fixtures in e2e/conftest.py for better container management. - Cleaned up e2e test files related to CoreScouter and PIWebAPIScouter workflows.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from unittest.mock import ANY, AsyncMock, MagicMock, patch
|
||||
from unittest.mock import ANY, MagicMock, Mock, patch
|
||||
|
||||
from pytest import fixture, mark
|
||||
from pytest import fixture
|
||||
from sientia_do.notifications.models import NotificationLevel
|
||||
from sientia_do.temporal.constants import DATETIME_FORMAT_MS_WITH_TZ
|
||||
|
||||
@@ -44,16 +44,18 @@ def mongodb_activity(mock_mongodb_repository):
|
||||
database_name='test_db',
|
||||
logger=MagicMock(),
|
||||
notification_handler=MagicMock(),
|
||||
metrics_controller=AsyncMock(),
|
||||
metrics_controller=MagicMock(),
|
||||
)
|
||||
return mongo
|
||||
|
||||
|
||||
def test_close(mongodb_activity):
|
||||
@patch('scouter.activities.mongodb.SientiaMonitoring')
|
||||
def test_close(mock_sientia_monitoring, mongodb_activity):
|
||||
"""Test close"""
|
||||
mongodb_activity.close()
|
||||
|
||||
mongodb_activity.mongodb_repository.close.assert_called_once()
|
||||
mock_sientia_monitoring.shutdown.assert_called_once()
|
||||
|
||||
|
||||
def test_del(mongodb_activity):
|
||||
@@ -64,11 +66,10 @@ def test_del(mongodb_activity):
|
||||
mongodb_activity.close.assert_called_once()
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_load_latest_data_none_last_data_timestamp(mongodb_activity):
|
||||
def test_load_latest_data_none_last_data_timestamp(mongodb_activity):
|
||||
"""Test load_latest_data"""
|
||||
|
||||
mongodb_activity.mongodb_repository.find = AsyncMock(
|
||||
mongodb_activity.mongodb_repository.find = Mock(
|
||||
return_value=[
|
||||
{
|
||||
'name': 'test1',
|
||||
@@ -80,7 +81,7 @@ async def test_load_latest_data_none_last_data_timestamp(mongodb_activity):
|
||||
]
|
||||
)
|
||||
|
||||
result = await mongodb_activity.load_latest_data(
|
||||
result = mongodb_activity.load_latest_data(
|
||||
{
|
||||
'metadata': {'workflow_name': 'test_pipeline', 'schedule_name': 'test_schedule'},
|
||||
'collection_name': 'test_collection',
|
||||
@@ -103,11 +104,10 @@ async def test_load_latest_data_none_last_data_timestamp(mongodb_activity):
|
||||
]
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_load_latest_data_not_none_last_data_timestamp(mongodb_activity):
|
||||
def test_load_latest_data_not_none_last_data_timestamp(mongodb_activity):
|
||||
"""Test load_latest_data"""
|
||||
|
||||
mongodb_activity.mongodb_repository.find = AsyncMock(
|
||||
mongodb_activity.mongodb_repository.find = Mock(
|
||||
return_value=[
|
||||
{
|
||||
'name': 'test1',
|
||||
@@ -119,7 +119,7 @@ async def test_load_latest_data_not_none_last_data_timestamp(mongodb_activity):
|
||||
]
|
||||
)
|
||||
|
||||
result = await mongodb_activity.load_latest_data(
|
||||
result = mongodb_activity.load_latest_data(
|
||||
{
|
||||
'metadata': {'workflow_name': 'test_pipeline', 'schedule_name': 'test_schedule'},
|
||||
'collection_name': 'test_collection',
|
||||
@@ -148,16 +148,13 @@ async def test_load_latest_data_not_none_last_data_timestamp(mongodb_activity):
|
||||
]
|
||||
|
||||
|
||||
@mark.asyncio
|
||||
async def test_load_latest_data_error(mongodb_activity):
|
||||
def test_load_latest_data_error(mongodb_activity):
|
||||
"""Test load_latest_data"""
|
||||
mongodb_activity.mongodb_repository.find.side_effect = Exception('test')
|
||||
mongodb_activity.send_notification = MagicMock()
|
||||
mongodb_activity.send_notification_async = AsyncMock()
|
||||
mongodb_activity.emit_metric = AsyncMock()
|
||||
|
||||
try:
|
||||
await mongodb_activity.load_latest_data(
|
||||
mongodb_activity.load_latest_data(
|
||||
{
|
||||
'metadata': {'workflow_name': 'test_pipeline', 'schedule_name': 'test_schedule'},
|
||||
'collection_name': 'test_collection',
|
||||
@@ -167,7 +164,7 @@ async def test_load_latest_data_error(mongodb_activity):
|
||||
except Exception as e:
|
||||
assert str(e) == 'test'
|
||||
|
||||
mongodb_activity.send_notification_async.assert_called_once_with(
|
||||
mongodb_activity.send_notification.assert_called_once_with(
|
||||
metadata={'workflow_name': 'test_pipeline', 'schedule_name': 'test_schedule'},
|
||||
notification_id='MONGO_LOAD_ERROR',
|
||||
message='Error loading data from MongoDB: test',
|
||||
|
||||
Reference in New Issue
Block a user