SIENTIAPDE-1974

SIENTIAPDE-1974 Fix Sonar issues: reduce gather_read_tags complexity, import pytest as module

Move the per-pipeline read tag loop of gather_read_tags into
_add_pipeline_read_tags (cognitive complexity 16 -> ~6) and import pytest
as a module in test_mongo_db.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 10:32:06 -03:00
parent 0c9eaab3f5
commit 5b47726a64
2 changed files with 27 additions and 16 deletions

View File

@@ -1,14 +1,14 @@
from datetime import UTC, datetime
from unittest.mock import ANY, AsyncMock, MagicMock, call, patch
from pytest import fixture, mark, raises
import pytest
from sientia_do.notifications.models import NotificationLevel
from sientia_do.temporal.constants import DATETIME_FORMAT_MS_WITH_TZ
from orchestrator.activities.mongo_db import MongoDB
@fixture
@pytest.fixture
@patch('orchestrator.activities.mongo_db.MongoDBRepository')
def mongo_db(mongo_mock):
mongo = MongoDB(
@@ -294,7 +294,7 @@ def test_update_pipelines_timestamps_success(now_mock, mongo_db):
@patch('orchestrator.activities.mongo_db.now')
@mark.parametrize(
@pytest.mark.parametrize(
'pipelines', [[], [{'schedule_name': 'test1', 'namespace': 'test1', 'success': False}]]
)
def test_update_pipelines_timestamps_all_failed_stamps_nothing(now_mock, mongo_db, pipelines):
@@ -373,7 +373,7 @@ def test_update_pipelines_timestamps_failures_notified_together(now_mock, mongo_
Exception('timeout'),
]
with raises(RuntimeError, match='Failed to update 2 of 3 pipelines timestamps'):
with pytest.raises(RuntimeError, match='Failed to update 2 of 3 pipelines timestamps'):
mongo_db.update_pipelines_timestamps(input_data)
assert mongo_db.mongo_db_repository.update_one.call_count == 3
@@ -462,7 +462,7 @@ def test_delete_pipelines_timestamps_success(now_mock, mongo_db):
)
@mark.parametrize(
@pytest.mark.parametrize(
'pipelines', [[], [{'schedule_name': 'test1', 'namespace': 'test1', 'success': False}]]
)
def test_delete_pipelines_timestamps_all_failed_deletes_nothing(mongo_db, pipelines):