class FlowExecTestBase: """Base class for testing FlowExec classes.""" PARSER_ARGS = { 'check_status', 'context_date', 'concurrency_strategy', 'context', 'context_date', 'expected_status', 'help', 'max_concurrent_flows', 'reload', 'verbose', 'wait_until_complete', } # expected choices for some actions AGRS_CHOICES = { 'concurrency_strategy': ['SKIP', 'IGNORE', 'FAIL', 'WAIT'], 'expected_status': ['INGESTED', 'DOWNLOADED', 'POPULATED_RAW_TABLE'], 'reload': ['False', 'Soft', 'True'], } # all actions which has attribute required=True ARGS_REQUIRED = set() # default values for all actions (if they have default) ARGS_DEFAULTS = { 'concurrency_strategy': 'WAIT', 'context': '{}', 'expected_status': 'INGESTED', 'help': '==SUPPRESS==', 'max_concurrent_flows': 5, 'skip': 1, 'verbose': False } def _get_actions_map(self): parser = self.flow_exec.prepare_parser() args = {action.dest: action for action in parser._actions} return args def test_parser_expected_actions(self): actions = self._get_actions_map() assert set(actions.keys()) == set(self.PARSER_ARGS) def test_parser_required_actions(self): actions = self._get_actions_map() required_actions = {k for k, v in actions.items() if v.required} assert required_actions == set(self.ARGS_REQUIRED) def test_parser_actions_choices(self): actions = self._get_actions_map() actions_choices = { k: v.choices for k, v in actions.items() if v.choices} assert actions_choices == self.AGRS_CHOICES def test_parser_actions_defaults(self): actions = self._get_actions_map() actions_defaults = { k: v.default for k, v in actions.items() if v.default is not None} assert actions_defaults == self.ARGS_DEFAULTS def test_generate_contexts(self): result = list(self.flow_exec.generate_contexts()) assert result == [{}]