Exemple #1
0
def test_run():
    event = get_initialized_test_event()
    step = Step(actions=[
        AddOrderLogEntry({
            "order": {
                "variable": "order"
            },
            "message": {
                "constant": "It Works."
            },
            "message_identifier": {
                "constant": "test_run"
            },
        })
    ],
                next=StepNext.STOP)
    script = Script(event_identifier=event.identifier, name="Test Script")
    script.set_steps([step])
    script.save()
    event.run()
    # The script is disabled by default, of course it won't run
    assert not event.variable_values["order"].log_entries.filter(
        identifier="test_run").exists()

    # Let's try that again.
    script.enabled = True
    script.save()
    event.run()
    assert event.variable_values["order"].log_entries.filter(
        identifier="test_run").exists()
    script.delete()
Exemple #2
0
def test_none_condop():
    step = Step(cond_op=StepConditionOperator.NONE,
                conditions=[
                    NonEmpty({"v": {
                        "variable": "a"
                    }}),
                    NonEmpty({"v": {
                        "variable": "b"
                    }}),
                ],
                actions=[SetDebugFlag({})])
    context = Context.from_variables(a=False, b=False)
    step.execute(context)
    assert context.get("debug")
Exemple #3
0
def test_condops(cond_op):
    step = Step(cond_op=cond_op,
                conditions=[
                    NonEmpty({"v": {
                        "variable": "a"
                    }}),
                    NonEmpty({"v": {
                        "variable": "b"
                    }}),
                ],
                actions=[SetDebugFlag({})])
    context = Context.from_variables(a=True, b=False)
    step.execute(context)
    if cond_op == StepConditionOperator.ALL:
        assert not context.get("debug")
    elif cond_op == StepConditionOperator.ANY:
        assert context.get("debug")
    elif cond_op == StepConditionOperator.NONE:
        assert not context.get("debug")
    else:
        raise ValueError("Unexpected condop %r" % cond_op)
Exemple #4
0
def test_conditionless_step_executes():
    step = Step(actions=[SetDebugFlag({})])
    context = Context()
    step.execute(context)
    assert context.get("debug")