Exemplo n.º 1
0
def test_list_valid_2():
    """Should be ok"""

    test_list = List(property=String(validators=[min_length(3)]))
    test_list.validate(['abcdef'])

    assert True
Exemplo n.º 2
0
def test_list_valid_1():
    """Should be ok"""

    test_list = List(validators=[min_length(3)])
    test_list.validate([3, 5, 9])

    assert True
Exemplo n.º 3
0
def test_string_invalid_2():
    """'fo' is too short"""

    test_string = String(validators=[min_length(3)])

    with assert_raises(InvalidPropertyError) as cm:
        test_string.validate('fo')

    assert cm.exception.error == 'invalid'
Exemplo n.º 4
0
def test_list_invalid_3():
    """List is too short"""

    test_list = List(validators=[min_length(3)])

    with assert_raises(InvalidPropertyError) as cm:
        test_list.validate([3, 5])

    assert cm.exception.error == 'invalid'
Exemplo n.º 5
0
def test_list_invalid_3():
    """List is too short"""

    test_list = List(validators=[min_length(3)])

    with assert_raises(InvalidPropertyError) as cm:
        test_list.validate([3, 5])

    assert cm.exception.error == 'invalid'
Exemplo n.º 6
0
def test_property_context():
    """Test context-aware property validators"""

    test_property = String(validators=[min_length(2, context='foo')])

    test_property.validate('a')
    test_property.validate('ab', context='foo')

    with assert_raises(InvalidPropertyError):
        test_property.validate('a', context='foo')
Exemplo n.º 7
0
def test_property_context():
    """Test context-aware property validators"""

    test_property = String(validators=[min_length(2, context='foo')])

    test_property.validate('a')
    test_property.validate('ab', context='foo')

    with assert_raises(InvalidPropertyError):
        test_property.validate('a', context='foo')
Exemplo n.º 8
0
class Animal(Model):
    name = String(validators=[
        min_length(5, context='colloquial'),
        min_length(10, context='academic')
    ])