Esempio n. 1
0
class PgNote(pwpgsql.Model):
    message = peewee.TextField()
    published_at = peeweext.fields.DatetimeTZField(null=True)

    @val.validates(val.ExclusionValidator('raise'),
                   val.LengthValidator(min_length=3, max_length=6))
    def validate_message(self, value):
        if value != 'hello':
            raise val.ValidationError

    def validate_nothing(self, value):
        return 'nothing'
Esempio n. 2
0
def test_length():
    validator = validation.LengthValidator(1, 3)
    validator('123')
    with pytest.raises(validation.ValidationError):
        validator('1234')