def test_execute_pipe(mocked_config): mocked_config.settings.dry_run = False piped_rule = ExampleRule(name="Test", param=None) piped_rule.execute = Mock() rule = ExampleRule(name="Test", param="Rule", pipe=piped_rule) rule.execute() # Asserting that the output of the original rule - which in this case # the input as well - is passed to the piped rule as an input. piped_rule.execute.assert_called_once_with(rule.param)
def test_cannot_proceed_dry_run(config): config.dry_run = True rule = ExampleRule(name="Test", param="Rule") rule.pre_task_hook = Mock() rule.post_task_hook = Mock() with pytest.raises(AssertionError) as exc: rule.execute("Rule") assert str(exc.value) == '"Test" cannot proceed because of dry run' assert not rule.pre_task_hook.called assert not rule.post_task_hook.called
def test_executed(name: str, param: Any, mocked_config): mocked_config.settings.dry_run = False rule = ExampleRule(name=name, param=param) rule.pre_task_hook = Mock() rule.post_task_hook = Mock() rule.task = Mock() rule.execute(param) rule.task.assert_called_once_with() rule.pre_task_hook.assert_called_once_with() rule.post_task_hook.assert_called_once_with()
def test_executed_no_direct_param(mocked_config): """ This test case covers the situation of piped and child rules which has no direct parameter (it is set to None), but getting it from the output of the previous rule as an input. """ mocked_config.settings.dry_run = False rule = ExampleRule(name="Test", param=None) rule.param = "Rule" rule.pre_task_hook = Mock() rule.post_task_hook = Mock() rule.task = Mock() rule.execute() rule.task.assert_called_once_with() rule.pre_task_hook.assert_called_once_with() rule.post_task_hook.assert_called_once_with()
def test_execute_children(mocked_config): mocked_config.settings.dry_run = False child_rule_1 = ExampleRule(name="Test", param=None) child_rule_1.execute = Mock() child_rule_2 = ExampleRule(name="Test", param=None) child_rule_2.execute = Mock() child_rule_3 = ExampleRule(name="Test", param=None) child_rule_3.execute = Mock() rule = ExampleRule(name="Test", param="Rule", children=[child_rule_1, child_rule_2, child_rule_3]) rule.execute() child_rule_1.execute.assert_called_once_with(rule.param) child_rule_2.execute.assert_called_once_with(rule.param) child_rule_3.execute.assert_called_once_with(rule.param)
def test_cannot_proceed_precondition(mocked_config): mocked_config.settings.dry_run = False rule = ExampleRule( name="Test", param="Rule", preconditions=( copy.deepcopy(FAILING_PRECONDITION), copy.deepcopy(PASSING_PRECONDITION), ), ) rule.pre_task_hook = Mock() rule.post_task_hook = Mock() with pytest.raises(PreconditionFailedError) as exc: rule.execute("Rule") assert str(exc.value) == '"Test" cannot proceed' assert not rule.pre_task_hook.called assert not rule.post_task_hook.called