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:
vitor-aignosi
2026-05-25 12:58:03 -03:00
parent 909ad25b63
commit 34dbc886f3
65 changed files with 2591 additions and 2849 deletions

View File

@@ -1,5 +1,5 @@
from datetime import datetime
from unittest.mock import ANY, AsyncMock, MagicMock, patch
from unittest.mock import ANY, MagicMock, Mock, patch
import numpy as np
import pytest
@@ -79,8 +79,7 @@ def test_redis_initialization(mock_redis_repository):
assert activity.redis_repository is not None
@pytest.mark.asyncio
async def test_get_last_data_timestamp_none(redis_activity):
def test_get_last_data_timestamp_none(redis_activity):
"""Test get_last_data_timestamp"""
test_data = {
**metadata,
@@ -88,9 +87,9 @@ async def test_get_last_data_timestamp_none(redis_activity):
'schedule_name': 'test_schedule',
}
redis_activity.redis_repository.get = AsyncMock(return_value=None)
redis_activity.redis_repository.get = Mock(return_value=None)
result = await redis_activity.get_last_data_timestamp(test_data)
result = redis_activity.get_last_data_timestamp(test_data)
redis_activity.redis_repository.get.assert_called_once_with(
'last_data_timestamp:test_pipeline:test_schedule',
@@ -100,14 +99,13 @@ async def test_get_last_data_timestamp_none(redis_activity):
assert result is None
@pytest.mark.asyncio
async def test_get_last_data_timestamp_not_none(redis_activity):
def test_get_last_data_timestamp_not_none(redis_activity):
"""Test get_last_data_timestamp"""
test_data = {**metadata, 'workflow_name': 'test_pipeline', 'schedule_name': 'test_schedule'}
redis_activity.redis_repository.get = AsyncMock(return_value='2023-01-01 12:00:00')
redis_activity.redis_repository.get = Mock(return_value='2023-01-01 12:00:00')
result = await redis_activity.get_last_data_timestamp(test_data)
result = redis_activity.get_last_data_timestamp(test_data)
redis_activity.redis_repository.get.assert_called_once_with(
'last_data_timestamp:test_pipeline:test_schedule',
@@ -117,21 +115,20 @@ async def test_get_last_data_timestamp_not_none(redis_activity):
assert result == '2023-01-01 12:00:00'
@pytest.mark.asyncio
async def test_get_last_data_timestamp_error(redis_activity):
def test_get_last_data_timestamp_error(redis_activity):
"""Test get_last_data_timestamp error"""
test_data = {**metadata, 'workflow_name': 'test_pipeline', 'schedule_name': 'test_schedule'}
redis_activity.send_notification_async = AsyncMock()
redis_activity.send_notification = Mock()
redis_activity.redis_repository.get.side_effect = Exception('test')
try:
await redis_activity.get_last_data_timestamp(test_data)
redis_activity.get_last_data_timestamp(test_data)
except Exception as e:
assert str(e) == 'test'
redis_activity.send_notification_async.assert_called_once_with(
redis_activity.send_notification.assert_called_once_with(
metadata=metadata['metadata'],
notification_id='REDIS_GET_ERROR',
message='Error getting last data timestamp: test',
@@ -144,8 +141,7 @@ async def test_get_last_data_timestamp_error(redis_activity):
raise AssertionError('Expected exception')
@pytest.mark.asyncio
async def test_put_last_data_timestamp_empty_dataframe(redis_activity):
def test_put_last_data_timestamp_empty_dataframe(redis_activity):
"""Test put_last_data_timestamp with empty dataframe"""
test_data = {
**metadata,
@@ -156,15 +152,14 @@ async def test_put_last_data_timestamp_empty_dataframe(redis_activity):
redis_activity.redis_repository.set = MagicMock()
result = await redis_activity.put_last_data_timestamp(test_data)
result = redis_activity.put_last_data_timestamp(test_data)
assert result is None
redis_activity.redis_repository.set.assert_not_called()
@pytest.mark.asyncio
async def test_put_last_data_timestamp_not_empty_dataframe(redis_activity):
def test_put_last_data_timestamp_not_empty_dataframe(redis_activity):
"""Test put_last_data_timestamp with not empty dataframe"""
data = DataFrame(
@@ -181,9 +176,9 @@ async def test_put_last_data_timestamp_not_empty_dataframe(redis_activity):
'data': data.to_dict('records'),
}
redis_activity.redis_repository.set = AsyncMock()
redis_activity.redis_repository.set = Mock()
result = await redis_activity.put_last_data_timestamp(test_data)
result = redis_activity.put_last_data_timestamp(test_data)
assert result == '2023-01-01 12:00:01'
@@ -195,8 +190,7 @@ async def test_put_last_data_timestamp_not_empty_dataframe(redis_activity):
)
@pytest.mark.asyncio
async def test_put_last_data_timestamp_error(redis_activity):
def test_put_last_data_timestamp_error(redis_activity):
"""Test put_last_data_timestamp error"""
test_data = {
**metadata,
@@ -211,16 +205,16 @@ async def test_put_last_data_timestamp_error(redis_activity):
).to_dict('records'),
}
redis_activity.send_notification_async = AsyncMock()
redis_activity.redis_repository.set = AsyncMock(side_effect=Exception('test'))
redis_activity.send_notification = Mock()
redis_activity.redis_repository.set = Mock(side_effect=Exception('test'))
try:
await redis_activity.put_last_data_timestamp(test_data)
redis_activity.put_last_data_timestamp(test_data)
except Exception as e:
assert str(e) == 'test'
redis_activity.send_notification_async.assert_called_once_with(
redis_activity.send_notification.assert_called_once_with(
metadata=metadata['metadata'],
notification_id='REDIS_SET_ERROR',
message='Error setting last data timestamp: test',
@@ -233,8 +227,7 @@ async def test_put_last_data_timestamp_error(redis_activity):
raise AssertionError('Expected exception')
@pytest.mark.asyncio
async def test_group_and_hold_data_new_key(redis_activity):
def test_group_and_hold_data_new_key(redis_activity):
"""Test group_and_hold_data with a new key"""
# Setup
test_data = {
@@ -255,11 +248,11 @@ async def test_group_and_hold_data_new_key(redis_activity):
}
# Mock get to return None for new key
redis_activity.redis_repository.get = AsyncMock(return_value=None)
redis_activity.redis_repository.set = AsyncMock()
redis_activity.redis_repository.get = Mock(return_value=None)
redis_activity.redis_repository.set = Mock()
# Call the method
result = await redis_activity.group_and_hold_data(test_data)
result = redis_activity.group_and_hold_data(test_data)
# Verify the result
expected_result = {
@@ -279,8 +272,7 @@ async def test_group_and_hold_data_new_key(redis_activity):
)
@pytest.mark.asyncio
async def test_group_and_hold_data_update_existing_fill_missing(redis_activity):
def test_group_and_hold_data_update_existing_fill_missing(redis_activity):
"""Test updating existing data with group_and_hold_data"""
# Setup initial data in Redis
existing_data = {'sensor1': 20.0, 'sensor2': 28.0, 'timestamp': '2023-01-01 11:00:00'}
@@ -309,11 +301,11 @@ async def test_group_and_hold_data_update_existing_fill_missing(redis_activity):
}
# Mock get to return existing data
redis_activity.redis_repository.get = AsyncMock(return_value=existing_data)
redis_activity.redis_repository.set = AsyncMock()
redis_activity.redis_repository.get = Mock(return_value=existing_data)
redis_activity.redis_repository.set = Mock()
# Call the method
result = await redis_activity.group_and_hold_data(test_data)
result = redis_activity.group_and_hold_data(test_data)
# Verify the result
expected_result = {
@@ -344,8 +336,7 @@ async def test_group_and_hold_data_update_existing_fill_missing(redis_activity):
)
@pytest.mark.asyncio
async def test_group_and_hold_data_with_none_values(redis_activity):
def test_group_and_hold_data_with_none_values(redis_activity):
"""Test handling of None values in group_and_hold_data"""
# Setup test data with None values
test_data = {
@@ -366,19 +357,18 @@ async def test_group_and_hold_data_with_none_values(redis_activity):
}
# Mock get to return None for new key
redis_activity.redis_repository.get = AsyncMock(return_value=None)
redis_activity.redis_repository.set = AsyncMock()
redis_activity.redis_repository.get = Mock(return_value=None)
redis_activity.redis_repository.set = Mock()
# Call the method
result = await redis_activity.group_and_hold_data(test_data)
result = redis_activity.group_and_hold_data(test_data)
# Verify None was converted to np.nan and values are as expected
assert np.isnan(result['value'][0])
assert result['value'][1] == pytest.approx(30.0)
@pytest.mark.asyncio
async def test_group_and_hold_data_empty_dataframe(redis_activity):
def test_group_and_hold_data_empty_dataframe(redis_activity):
"""Test group_and_hold_data with empty DataFrame"""
# Setup test with empty data
test_data = {
@@ -391,16 +381,15 @@ async def test_group_and_hold_data_empty_dataframe(redis_activity):
'fill_missing_tags': False,
}
redis_activity.redis_repository.get = AsyncMock(return_value=None)
redis_activity.redis_repository.get = Mock(return_value=None)
# Call the method
result = await redis_activity.group_and_hold_data(test_data)
result = redis_activity.group_and_hold_data(test_data)
assert result == {}
@pytest.mark.asyncio
async def test_group_and_hold_data_error_get(redis_activity):
def test_group_and_hold_data_error_get(redis_activity):
"""Test group_and_hold_data error"""
test_data = {
**metadata,
@@ -413,16 +402,16 @@ async def test_group_and_hold_data_error_get(redis_activity):
'fill_missing_tags': False,
}
redis_activity.redis_repository.get = AsyncMock(side_effect=Exception('test'))
redis_activity.send_notification_async = AsyncMock()
redis_activity.redis_repository.get = Mock(side_effect=Exception('test'))
redis_activity.send_notification = Mock()
try:
await redis_activity.group_and_hold_data(test_data)
redis_activity.group_and_hold_data(test_data)
except Exception as e:
assert str(e) == 'test'
redis_activity.send_notification_async.assert_called_once_with(
redis_activity.send_notification.assert_called_once_with(
metadata=metadata['metadata'],
notification_id='REDIS_GET_ERROR',
message='Error getting held data: test',
@@ -435,8 +424,7 @@ async def test_group_and_hold_data_error_get(redis_activity):
raise AssertionError('Expected exception')
@pytest.mark.asyncio
async def test_group_and_hold_data_error_set(redis_activity):
def test_group_and_hold_data_error_set(redis_activity):
"""Test group_and_hold_data error"""
test_data = {
**metadata,
@@ -452,21 +440,20 @@ async def test_group_and_hold_data_error_set(redis_activity):
existing_data = {'sensor1': 20.0, 'sensor2': 28.0, 'timestamp': '2023-01-01 11:00:00'}
# Mock get to return existing data
redis_activity.redis_repository.get = AsyncMock(return_value=existing_data)
redis_activity.redis_repository.set = AsyncMock(side_effect=Exception('test'))
redis_activity.send_notification_async = AsyncMock()
redis_activity.redis_repository.get = Mock(return_value=existing_data)
redis_activity.redis_repository.set = Mock(side_effect=Exception('test'))
redis_activity.send_notification = Mock()
try:
await redis_activity.group_and_hold_data(test_data)
redis_activity.group_and_hold_data(test_data)
except Exception as e:
assert str(e) == 'test'
@pytest.mark.asyncio
async def test_store_data_package(redis_activity):
def test_store_data_package(redis_activity):
"""Test store_data_package"""
redis_activity.redis_repository.set = AsyncMock()
redis_activity.redis_repository.set = Mock()
test_data = {
**metadata,
@@ -489,7 +476,7 @@ async def test_store_data_package(redis_activity):
'model_tags': {'sensor1': 'sensor1', 'sensor2': 'sensor2'},
}
await redis_activity.store_data_package(test_data)
redis_activity.store_data_package(test_data)
redis_activity.redis_repository.set.assert_called_once_with(
ANY,
@@ -499,11 +486,10 @@ async def test_store_data_package(redis_activity):
)
@pytest.mark.asyncio
async def test_store_data_package_error(redis_activity):
def test_store_data_package_error(redis_activity):
"""Test store_data_package error"""
redis_activity.redis_repository.set = AsyncMock(side_effect=ValueError('test'))
redis_activity.send_notification_async = AsyncMock()
redis_activity.redis_repository.set = Mock(side_effect=ValueError('test'))
redis_activity.send_notification = Mock()
test_data = {
**metadata,
@@ -527,9 +513,9 @@ async def test_store_data_package_error(redis_activity):
}
with pytest.raises(ValueError):
await redis_activity.store_data_package(test_data)
redis_activity.store_data_package(test_data)
redis_activity.send_notification_async.assert_called_once_with(
redis_activity.send_notification.assert_called_once_with(
metadata=metadata['metadata'],
notification_id='REDIS_SET_ERROR',
message='Error setting data package: test',