Пример #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
Пример #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
Пример #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'
Пример #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'
Пример #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'
Пример #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')
Пример #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')
Пример #8
0
class Animal(Model):
    name = String(validators=[
        min_length(5, context='colloquial'),
        min_length(10, context='academic')
    ])