"""Unit tests for Spotify Marketshare Week Ending Workflow.""" from unittest import mock from unittest.mock import MagicMock from feed_ingestion.flows.spotify_marketshare_week_ending.flow import Flow def test_decider(): """Test normal decider execution.""" schedule = MagicMock() schedule_result_object = MagicMock() schedule_result_object.result = {} schedule.return_value = schedule_result_object flow = Flow() flow.decider(schedule) schedule.assert_has_calls([ mock.call('bootstrap', mock.ANY), mock.call('fetch_from_drop_location', mock.ANY, requires=mock.ANY), mock.call('set_status_to_downloaded', mock.ANY, requires=mock.ANY), mock.call('create_temp_staging_raw_table', mock.ANY, requires=mock.ANY), mock.call('load_temp_staging_raw_table', mock.ANY, requires=mock.ANY), mock.call('load_staging_raw_table', mock.ANY, requires=mock.ANY), mock.call('set_status_to_ingested', mock.ANY, requires=mock.ANY), ]) def test_decider_should_stop_when_files_not_found(): """Decider quits if files not found.""" bootstrap = MagicMock() bootstrap.result = {'fetch_from_drop_location.stop': True} schedule = MagicMock(return_value=bootstrap) flow = Flow() flow.decider(schedule) schedule.assert_has_calls([ mock.call('bootstrap', mock.ANY), mock.call('fetch_from_drop_location', mock.ANY, requires=mock.ANY) ]) assert schedule.return_value.result == { 'fetch_from_drop_location.stop': True}