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")
def test_basic_exec(): script = get_test_script() # `en` is not in the conditions context = Context.from_variables(order_language="en") script.execute(context) assert not context.get("success") # `fi` is matched by the first condition and cond_op is 'or' context = Context.from_variables(order_language="fi") script.execute(context) assert context.get("success") # `ja` is matched by the other condition, and cond_op is 'or' context = Context.from_variables(order_language="ja") script.execute(context) assert context.get("success")
def test_disabled_steps(): script = get_test_script() steps = script.get_steps() steps[0].enabled = False script.set_steps(steps) # Disabled steps don't run context = Context.from_variables() script.execute(context) assert not context.get("success")
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")
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)
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)
def test_binding_fallthrough(): ctx = Context.from_variables() b = Binding("x", default="foo") assert b.get_value(ctx, {"variable": "var"}) == "foo" assert b.get_value(ctx, {}) == "foo"
def test_empty(): ie = Empty({"v": {"variable": "v"}}) assert ie.test(Context.from_variables(v=False)) assert ie.test(Context.from_variables(v=())) assert ie.test(Context.from_variables(v=0)) assert not ie.test(Context.from_variables(v=6))
def test_non_empty(): ie = NonEmpty({"v": {"variable": "v"}}) assert ie.test(Context.from_variables(v=True)) assert not ie.test(Context.from_variables(v="")) assert not ie.test(Context.from_variables(v=0))
def test_text_equal(): ie = TextEqual({"v1": {"variable": "v"}, "v2": {"constant": " Foo "}}) assert ie.test(Context.from_variables(v="foo")) assert ie.test(Context.from_variables(v="Foo")) assert ie.test(Context.from_variables(v="Foo ")) assert not ie.test(Context.from_variables(v="faa"))
def test_integer_equals(): ie = IntegerEqual({"v1": {"variable": "v"}, "v2": {"constant": 42}}) assert ie.test(Context.from_variables(v=42)) assert ie.test(Context.from_variables(v="42")) assert not ie.test(Context.from_variables(v="442")) assert not ie.test(Context.from_variables(v=True))
def test_conditionless_step_executes(): step = Step(actions=[SetDebugFlag({})]) context = Context() step.execute(context) assert context.get("debug")