"""Unit tests for iTunes Workflow.""" from unittest import mock from unittest.mock import MagicMock from garcon_contrib.dynamo_feed_status import garcon_feed_status from feed_ingestion.flows.itunes.flow import Flow def test_decider_concurrent_status_stop(): """Test decider execution when concurrent flows are running.""" check_concurrent_status = MagicMock() check_concurrent_status.result = { 'check_concurrent_status.stop': True} schedule = MagicMock(return_value=check_concurrent_status) flow = Flow() flow.decider(schedule) schedule.assert_has_calls([ mock.call('check_concurrent_status', mock.ANY)]) def test_decider_files_not_available(): """Test decider execution when files not available.""" update_feed_file_status = MagicMock() update_feed_file_status.result = { 'feed_file_status.file_status': garcon_feed_status.STATUS_NOT_AVAILABLE } schedule = MagicMock(return_value=update_feed_file_status) flow = Flow() flow.decider(schedule) schedule.assert_has_calls([ mock.call('check_concurrent_status', mock.ANY), mock.call('bootstrap', mock.ANY, requires=mock.ANY), mock.call('reporter_to_s3', mock.ANY, requires=mock.ANY), mock.call('update_feed_file_status', mock.ANY, requires=mock.ANY), ]) def test_decider_should_load_data_into_fact_analytics(): """Test decider if load_fact_analytics is True.""" update_feed_file_status = MagicMock() update_feed_file_status.result = { 'feed_file_status.file_status': garcon_feed_status.STATUS_DOWNLOADED } schedule = MagicMock(return_value=update_feed_file_status) flow = Flow() flow.decider(schedule) schedule.assert_has_calls([ mock.call('check_concurrent_status', mock.ANY), mock.call('bootstrap', mock.ANY, requires=mock.ANY), mock.call('reporter_to_s3', mock.ANY, requires=mock.ANY), mock.call('update_feed_file_status', mock.ANY, requires=mock.ANY), mock.call('check_available_reports', mock.ANY, requires=mock.ANY), mock.call('set_status_to_downloaded', mock.ANY, requires=mock.ANY), mock.call('load_temp_table', mock.ANY, requires=mock.ANY), mock.call('clear_staging_raw_itunes', mock.ANY, requires=mock.ANY), mock.call('load_staging_raw_itunes', mock.ANY, requires=mock.ANY), mock.call('set_populated_status', mock.ANY, requires=mock.ANY), mock.call('insert_new_zipcode', mock.ANY, requires=mock.ANY), mock.call('update_apple_id_mapping', mock.ANY, requires=mock.ANY), mock.call('update_upc_isrc_on_staging_raw', mock.ANY, requires=mock.ANY), mock.call('load_staging_fact', mock.ANY, requires=mock.ANY), mock.call('load_fact_tables', mock.ANY, requires=mock.ANY), ])