示例#1
0
class MyNote(pwmysql.Model):
    message = peewee.TextField()
    published_at = peeweext.fields.DatetimeTZField(null=True)

    @val.validates(val.ExclusionValidator('raise error'))
    def validate_message(self, value):
        pass
示例#2
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'
示例#3
0
def test_exclusion():
    validator = validation.ExclusionValidator(1, 2, 3)
    validator(4)
    with pytest.raises(validation.ValidationError):
        validator(1)