"""Unit tests for the flow class of datadog_caching_monitor.""" from unittest import mock from unittest.mock import MagicMock from swf_monitoring.flows.datadog_caching_monitor.flow import Flow def test_decider(): """Test normal decider execution.""" populate_cache_stats = MagicMock() populate_cache_stats.result = {'populate_cache_stats.stop': False} schedule = MagicMock(return_value=populate_cache_stats) flow = Flow() flow.decider(schedule) schedule.assert_has_calls([ mock.call('populate_cache_stats', mock.ANY), mock.call( 'update_metadata_in_cache_stats_table', mock.ANY, requires=[mock.ANY]), mock.call( 'send_query_level_metrics_to_datadog', mock.ANY, requires=[mock.ANY]), mock.call( 'send_hits_to_kw_cache_percentage_to_datadog', mock.ANY, requires=[mock.ANY]), ]) def test_decider_should_stop_when_metadata_query_timed_out(): """Decider quits if a Snowflake metadata query timed out.""" populate_cache_stats = MagicMock() populate_cache_stats.result = {'populate_cache_stats.stop': True} schedule = MagicMock(return_value=populate_cache_stats) flow = Flow() result = flow.decider(schedule) assert result == {'result': 'Metadata query timeouted'} schedule.assert_has_calls([mock.call('populate_cache_stats', mock.ANY)]) assert schedule.call_count == 1