import argparse import pytest from feed_ingestion.flows.tiktok import exec # noqa:A004 from tests.test_exec_flow import FlowExecTestBase from tests.testing_utils import parametrize_by_dicts, raises_optionally class TestFlowExec(FlowExecTestBase): @pytest.fixture(autouse=True) def setup(self): self.flow_exec = exec.FlowExec() PARSER_ARGS = FlowExecTestBase.PARSER_ARGS | { 'licensor', 'report', 'days', 'skip', 'build_dbt', 'use_sme_s3', } ARGS_REQUIRED = FlowExecTestBase.ARGS_REQUIRED | { 'licensor', 'report'} AGRS_CHOICES = FlowExecTestBase.AGRS_CHOICES | { 'licensor': ['ALL', 'theorchard', 'sme', 'smejp', 'smejpintl', 'altafonte'], 'report': ['ALL', 'TikTok', 'Douyin'], } ARGS_DEFAULTS = FlowExecTestBase.ARGS_DEFAULTS @parametrize_by_dicts( 'args, expected, raises', [ dict( case='one licensor, one report', args=argparse.Namespace( licensor='sme', report='TikTok', ), expected=[ {'licensor': 'sme', 'reports': 'TikTok'}, ] ), dict( case='ALL licensors, one report', args=argparse.Namespace( licensor='ALL', report='TikTok', ), expected=[ {'licensor': 'theorchard', 'reports': 'TikTok'}, {'licensor': 'sme', 'reports': 'TikTok'}, {'licensor': 'smejp', 'reports': 'TikTok'}, {'licensor': 'smejpintl', 'reports': 'TikTok'}, {'licensor': 'altafonte', 'reports': 'TikTok'}, ] ), dict( case='None licensor, None reports', args=argparse.Namespace( licensor=None, report=None, ), expected=[{}] ), dict( case='one licensor, All reports', args=argparse.Namespace( licensor='sme', report='ALL', ), expected=[ {'licensor': 'sme', 'reports': 'TikTok'}, {'licensor': 'sme', 'reports': 'Douyin'}, ] ), ] ) def test_generate_contexts(self, args, expected, raises): self.flow_exec.args = args with raises_optionally(raises): contexts = self.flow_exec.generate_contexts() assert list(contexts) == expected