Exemplo n.º 1
0
def test_validate_function_accepts_validate_as_argument():
    """Function validate() accepts a  of additional validators to run."""
    int_value = 123
    not_int_value = 'abc'

    assert validate('new_field', int_value, validate_as='integer')

    with raises(ValidationError):
        assert validate('new_field', not_int_value, validate_as='integer')
Exemplo n.º 2
0
def test_validate_function_uses_validation_functions_dict():
    """Function validate() uses validation_functions dict to validate
    values."""
    integer = 1234
    domain = 'example.com'

    assert validate('integer', integer)
    assert validate('domain', domain)

    with raises(ValidationError):
        validate('ttl', domain)
Exemplo n.º 3
0
def test_validate_function_allows_for_optional_fields():
    """Function validate() allows for optional fields."""
    assert validate('domain', None, optional=True)
    assert validate('domain', '', optional=True)

    with raises(ValidationError):
        validate('domain', '')

    with raises(ValidationError):
        validate('domain', None)

    # But this should not raise an error
    assert validate('domain', 0)
Exemplo n.º 4
0
def test_validate_function_still_checks_given_optional_fields():
    """Function validate() validates optional fields if they are given."""
    optional_int = 'abcd'

    with raises(ValidationError):
        validate('ttl', optional_int)