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
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'
def test_exclusion(): validator = validation.ExclusionValidator(1, 2, 3) validator(4) with pytest.raises(validation.ValidationError): validator(1)