示例#1
0
def test_validate_param_required():
    rule = ExampleRule(name="Test", param="Rule")

    with pytest.raises(ValueError) as exc:
        rule.validate(val=None, cast_to=str, required=True)

    assert str(exc.value) == "The given value is empty"
示例#2
0
def test_validate_param_required():
    rule = ExampleRule(name="Test", param="Rule")

    with pytest.raises(ValueError) as exc:
        rule.validate(val=None, cast_to=str, required=True)

    assert (
        str(exc.value) ==
        f"Parameter validation of {str(rule)} failed, the given value is empty"
    )
示例#3
0
def test_validate_param(value):
    rule = ExampleRule(name="Test", param="Rule")

    # Casting to string is the safest
    result = rule.validate(value, cast_to=str)

    assert result == str(value)
示例#4
0
def test_validate_param_empty():
    rule = ExampleRule(name="Test", param="Rule")

    result = rule.validate(val=None, cast_to=str)

    assert result == "None"
示例#5
0
def test_validate_no_casting(value):
    rule = ExampleRule(name="Test", param="Rule")

    result = rule.validate(val=value)

    assert result is value