test(orchestrator): cover mixed and empty timestamp updates/deletes (SIENTIAPDE-2192)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime
|
||||||
from unittest.mock import ANY, AsyncMock, MagicMock, patch
|
from unittest.mock import ANY, AsyncMock, MagicMock, patch
|
||||||
|
|
||||||
from pytest import fixture
|
from pytest import fixture, mark
|
||||||
from sientia_do.notifications.models import NotificationLevel
|
from sientia_do.notifications.models import NotificationLevel
|
||||||
from sientia_do.temporal.constants import DATETIME_FORMAT_MS_WITH_TZ
|
from sientia_do.temporal.constants import DATETIME_FORMAT_MS_WITH_TZ
|
||||||
|
|
||||||
@@ -266,12 +266,11 @@ def test_update_pipelines_timestamps_success(now_mock, mongo_db):
|
|||||||
|
|
||||||
|
|
||||||
@patch('orchestrator.activities.mongo_db.now')
|
@patch('orchestrator.activities.mongo_db.now')
|
||||||
def test_update_pipelines_timestamps_all_failed_stamps_nothing(now_mock, mongo_db):
|
@mark.parametrize(
|
||||||
input_data = {
|
'pipelines', [[], [{'schedule_name': 'test1', 'namespace': 'test1', 'success': False}]]
|
||||||
'updated_pipelines': [
|
)
|
||||||
{'schedule_name': 'test1', 'namespace': 'test1', 'success': False},
|
def test_update_pipelines_timestamps_all_failed_stamps_nothing(now_mock, mongo_db, pipelines):
|
||||||
]
|
input_data = {'updated_pipelines': pipelines}
|
||||||
}
|
|
||||||
mongo_db.mongo_db_repository.update_many = MagicMock()
|
mongo_db.mongo_db_repository.update_many = MagicMock()
|
||||||
|
|
||||||
mongo_db.update_pipelines_timestamps(input_data)
|
mongo_db.update_pipelines_timestamps(input_data)
|
||||||
@@ -281,6 +280,26 @@ def test_update_pipelines_timestamps_all_failed_stamps_nothing(now_mock, mongo_d
|
|||||||
mongo_db.mongo_db_repository.update_many.assert_not_called()
|
mongo_db.mongo_db_repository.update_many.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
@patch('orchestrator.activities.mongo_db.now')
|
||||||
|
def test_update_pipelines_timestamps_mixed_stamps_only_successes(now_mock, mongo_db):
|
||||||
|
input_data = {
|
||||||
|
'updated_pipelines': [
|
||||||
|
{'schedule_name': 'test1', 'namespace': 'test1', 'success': True},
|
||||||
|
{'schedule_name': 'test2', 'namespace': 'test2', 'success': False},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
mongo_db.mongo_db_repository.update_many = MagicMock()
|
||||||
|
|
||||||
|
mongo_db.update_pipelines_timestamps(input_data)
|
||||||
|
|
||||||
|
mongo_db.mongo_db_repository.update_many.assert_called_once_with(
|
||||||
|
'orchestrated_schedules',
|
||||||
|
{'$or': [{'schedule_name': 'test1', 'namespace': 'test1'}]},
|
||||||
|
{'$set': {'updated_at': now_mock.return_value}},
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch('orchestrator.activities.mongo_db.now')
|
@patch('orchestrator.activities.mongo_db.now')
|
||||||
def test_update_pipelines_timestamps_failure(now_mock, mongo_db):
|
def test_update_pipelines_timestamps_failure(now_mock, mongo_db):
|
||||||
input_data = {
|
input_data = {
|
||||||
@@ -378,12 +397,11 @@ def test_delete_pipelines_timestamps_success(now_mock, mongo_db):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_delete_pipelines_timestamps_all_failed_deletes_nothing(mongo_db):
|
@mark.parametrize(
|
||||||
input_data = {
|
'pipelines', [[], [{'schedule_name': 'test1', 'namespace': 'test1', 'success': False}]]
|
||||||
'deleted_pipelines': [
|
)
|
||||||
{'schedule_name': 'test1', 'namespace': 'test1', 'success': False},
|
def test_delete_pipelines_timestamps_all_failed_deletes_nothing(mongo_db, pipelines):
|
||||||
]
|
input_data = {'deleted_pipelines': pipelines}
|
||||||
}
|
|
||||||
mongo_db.mongo_db_repository.delete_many = MagicMock()
|
mongo_db.mongo_db_repository.delete_many = MagicMock()
|
||||||
|
|
||||||
mongo_db.delete_pipelines_timestamps(input_data)
|
mongo_db.delete_pipelines_timestamps(input_data)
|
||||||
@@ -393,6 +411,24 @@ def test_delete_pipelines_timestamps_all_failed_deletes_nothing(mongo_db):
|
|||||||
mongo_db.mongo_db_repository.delete_many.assert_not_called()
|
mongo_db.mongo_db_repository.delete_many.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
|
def test_delete_pipelines_timestamps_mixed_deletes_only_successes(mongo_db):
|
||||||
|
input_data = {
|
||||||
|
'deleted_pipelines': [
|
||||||
|
{'schedule_name': 'test1', 'namespace': 'test1', 'success': True},
|
||||||
|
{'schedule_name': 'test2', 'namespace': 'test2', 'success': False},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
mongo_db.mongo_db_repository.delete_many = MagicMock()
|
||||||
|
|
||||||
|
mongo_db.delete_pipelines_timestamps(input_data)
|
||||||
|
|
||||||
|
mongo_db.mongo_db_repository.delete_many.assert_called_once_with(
|
||||||
|
'orchestrated_schedules',
|
||||||
|
{'$or': [{'schedule_name': 'test1', 'namespace': 'test1'}]},
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@patch('orchestrator.activities.mongo_db.now')
|
@patch('orchestrator.activities.mongo_db.now')
|
||||||
def test_delete_pipelines_timestamps_failure(now_mock, mongo_db):
|
def test_delete_pipelines_timestamps_failure(now_mock, mongo_db):
|
||||||
input_data = {
|
input_data = {
|
||||||
|
|||||||
Reference in New Issue
Block a user