import pytest from feed_ingestion.flows.spotify_charts import exec # noqa:A004 def test_prepare_parser_args(): parser = exec.FlowExec().prepare_parser() expected_args = { 'chart', 'context_date', 'days', 'skip', 'reload', 'check_status', 'build_charts' } args = {action.dest for action in parser._actions} assert expected_args.issubset(args), expected_args.difference(args) @pytest.mark.parametrize( 'case_name, command_line, env, expected_args_props', [ ( 'chart by command line', '--chart weekly_top_songs', {}, dict( chart='weekly_top_songs', ) ), ( 'chart by env', '', {'CHART': 'daily_top_songs'}, dict( chart='daily_top_songs', ), ), ] ) def test_prepare_parser( case_name, command_line, env, expected_args_props, clear_os_environ, monkeypatch): argv = command_line.split() for key, value in env.items(): monkeypatch.setenv(key, value) parser = exec.FlowExec().prepare_parser() args = parser.parse_args(argv) for key, value in expected_args_props.items(): assert getattr(args, key) == value @pytest.mark.parametrize( 'case_name, command_line, env, expected_exception', [ ( 'wrong chart by command line', '--chart not_weekly_top_songs', {}, SystemExit ), ( 'wrong chart by ENV', '', {'CHART': 'not_weekly_top_songs'}, SystemExit ), ( 'no chart', '', {}, SystemExit ), ] ) def test_prepare_parser_negative( case_name, command_line, env, expected_exception, clear_os_environ, monkeypatch): argv = command_line.split() for key, value in env.items(): monkeypatch.setenv(key, value) with pytest.raises(expected_exception): parser = exec.FlowExec().prepare_parser() parser.parse_args(argv)