Beispiel #1
0
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
Beispiel #2
0
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()
Beispiel #3
0
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()
Beispiel #4
0
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