def test_list_valid_2(): """Should be ok""" test_list = List(property=String(validators=[min_length(3)])) test_list.validate(['abcdef']) assert True
def test_list_valid_1(): """Should be ok""" test_list = List(validators=[min_length(3)]) test_list.validate([3, 5, 9]) assert True
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'
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'
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')
class Animal(Model): name = String(validators=[ min_length(5, context='colloquial'), min_length(10, context='academic') ])