"""Unit tests for YouTube Video Report Workflow.""" from unittest.mock import MagicMock import pytest from feed_ingestion.flows.youtube_video.flow import Flow @pytest.mark.parametrize( 'test_case, params', [ [ 'theorchard normal flow', dict( context={}, swf_context={ 'bootstrap.licensor': 'theorchard', }, expected_tasks=[ 'bootstrap', 'grab_reports_files', 'source_files', 'create_temp_staging_raw_table', 'load_temp_staging_raw_table', 'clean_staging_raw_table', 'load_staging_raw_table', 'drop_temp_staging_raw_table', 'update_staging_raw_table', 'update_channel_names_table', 'update_mnc_and_owner_columns', 'set_status_to_ingested', ], ), ], [ 'theorchard skip grab_reports_files', dict( context={ 'skip_grab_reports_files': 'True', }, swf_context={ 'bootstrap.licensor': 'theorchard', }, expected_tasks=[ 'bootstrap', 'source_files', 'create_temp_staging_raw_table', 'load_temp_staging_raw_table', 'clean_staging_raw_table', 'load_staging_raw_table', 'drop_temp_staging_raw_table', 'update_staging_raw_table', 'update_channel_names_table', 'update_mnc_and_owner_columns', 'set_status_to_ingested', ], ), ], [ 'theorchard no files', dict( context={}, swf_context={ 'grab_reports_files.stop': True, 'bootstrap.licensor': 'theorchard', }, expected_tasks=[ 'bootstrap', 'grab_reports_files', ], ), ], [ 'bootstrap stop', dict( context={}, swf_context={ 'bootstrap.stop': True, 'bootstrap.licensor': 'theorchard', }, expected_tasks=[ 'bootstrap', ], ) ], [ 'sme normal flow', dict( context={}, swf_context={ 'bootstrap.licensor': 'sme', }, expected_tasks=[ 'bootstrap', 'sme_copy_from_athena_to_s3', 'source_files', 'create_temp_staging_raw_table', 'load_temp_staging_raw_table', 'clean_staging_raw_table', 'load_staging_raw_table', 'drop_temp_staging_raw_table', 'update_staging_raw_table', 'update_channel_names_table', 'update_mnc_and_owner_columns', 'set_status_to_ingested', ], ) ], [ 'sme no files', dict( context={}, swf_context={ 'sme_copy_from_athena_to_s3.stop': True, 'bootstrap.licensor': 'sme', }, expected_tasks=[ 'bootstrap', 'sme_copy_from_athena_to_s3', ], ), ], ] ) def test_decider(test_case, params): """Test case for decider execution.""" schedule = MagicMock() schedule.return_value.result = params['swf_context'] flow = Flow() flow.decider(schedule, params['context']) tasks = [ call.args[0] for call in schedule.call_args_list ] assert tasks == params['expected_tasks'] @pytest.mark.parametrize( 'case_name, params', [ [ 'theorchard', dict( context={ 'licensor': 'theorchard', 'date': '2020-01-01', }, expected='youtube_video_theorchard', ), ], [ 'sme', dict( context={ 'licensor': 'sme', 'date': '2020-01-01', }, expected='youtube_video_sme', ), ], ] ) def test_contextified_feed_name(case_name, params): """Test contextified_feed_name.""" flow = Flow() result = flow.contextified_feed_name(params['context']) assert result == params['expected'] @pytest.mark.parametrize( 'case_name, params', [ [ 'incorrect licensor', dict( context={ 'licensor': 'not_a_licensor', 'date': '2020-01-01', }, expected=AssertionError, ), ], [ 'no licensor', dict( context={ 'date': '2020-01-01', }, expected=AssertionError, ), ], ] ) def test_contextified_feed_name_negative(case_name, params): """Test negative cases of contextified_feed_name.""" flow = Flow() with pytest.raises(params['expected']): flow.contextified_feed_name(params['context'])