예제 #1
0
def test_base_form_amount_validator_with_valid_value():

    form = Form()
    amount_field = Field(13)  # valid amount

    try:
        validate_amount(form, amount_field)
    except:
        raise Exception("An error was raised despite a valid amount being provided")
예제 #2
0
def test_base_form_amount_validator_with_too_small_value():

    form = Form()
    # None is sent if value can't be casted to a float
    amount_field = Field(0.87)

    try:
        validate_amount(form, amount_field)
        raise Exception("A validation error should have been raised")
    except validators.ValidationError as e:
        assert str(e) == "Amount is less than 1"
    except:
        raise Exception("An error was raised, but not a validation one")
예제 #3
0
def test_base_form_amount_validator_with_non_numeric_value():

    form = Form()
    # None is sent from filter func if value can't be casted to a float
    amount_field = Field(None)

    try:
        validate_amount(form, amount_field)
        raise Exception("A validation error should have been raised")
    except validators.ValidationError as e:
        assert str(e) == "Non-numeric amount provided"
    except:
        raise Exception("An error was raised, but not a validation one")