Esempio n. 1
0
def test_bad_numeric_greater_than_path():
    rating_rule = ChoiceRule("$.rating", numeric_greater_than_path="$.auditThreshold")
    with pytest.raises(
        AWSStepFuncsValueError,
        match="numeric_greater_than_path must evaluate to a numeric value",
    ):
        rating_rule.evaluate({"rating": 53, "auditThreshold": "50"})
Esempio n. 2
0
def test_bad_string_equals_path():
    salary_rule = ChoiceRule("$.salary", string_equals_path="$.expectedSalary")
    with pytest.raises(
        AWSStepFuncsValueError,
        match="string_equals_path must evaluate to a string value",
    ):
        salary_rule.evaluate({"salary": "100_000", "expectedSalary": 100_000})
Esempio n. 3
0
def test_and_choice():
    next_state = PassState("Passing")
    and_choice = AndChoice(
        [
            ChoiceRule(variable="$.value", is_present=True),
            ChoiceRule(variable="$.value", numeric_greater_than_equals=20),
            ChoiceRule(variable="$.value", numeric_less_than=30),
        ],
        next_state=next_state,
    )

    assert and_choice.evaluate({"setting": "on", "value": 20})
    assert and_choice.evaluate({"setting": "on", "value": 25})
    assert not and_choice.evaluate({"setting": "on", "value": 30})
    assert not and_choice.evaluate({"setting": "on"})
    assert not and_choice.evaluate({"setting": "on", "value": 50})
Esempio n. 4
0
def test_choice_rule_repr():
    choice_rule = ChoiceRule("$.career", string_equals="Pirate")
    assert repr(
        choice_rule) == "ChoiceRule('$.career', string_equals='Pirate')"
Esempio n. 5
0
def test_string_less_than_equals_path():
    rule = ChoiceRule("$.letter", string_less_than_equals_path="$.compareLetter")
    assert rule.evaluate({"letter": "A", "compareLetter": "B"})
    assert rule.evaluate({"letter": "B", "compareLetter": "B"})
    assert not rule.evaluate({"letter": "C", "compareLetter": "B"})
Esempio n. 6
0
def test_string_less_than_equals():
    rule = ChoiceRule("$.letter", string_less_than_equals="B")
    assert rule.evaluate({"letter": "A"})
    assert rule.evaluate({"letter": "B"})
    assert not rule.evaluate({"letter": "C"})
Esempio n. 7
0
def test_string_equals_reference_path():
    career_rule = ChoiceRule("$.career", string_equals_path="$.expectedCareer")
    assert career_rule.evaluate({"career": "Pirate", "expectedCareer": "Pirate"})
    assert not career_rule.evaluate({"career": "Pirate", "expectedCareer": "Doctor"})
Esempio n. 8
0
def test_string_greater_than():
    rule = ChoiceRule("$.letter", string_greater_than="B")
    assert not rule.evaluate({"letter": "A"})
    assert rule.evaluate({"letter": "C"})
Esempio n. 9
0
def test_multiple_data_test_expressions():
    with pytest.raises(
        AWSStepFuncsValueError, match="Exactly one data-test expression must be defined"
    ):
        ChoiceRule("$.career", string_equals="Pirate", is_present=True)