class UserValidator(Validator): email = StringField(required=True, validators=[validate_email(), validate_email_unique]) name = StringField(required=True, validators=[validate_not_empty()]) description = StringField(required=True, validators=[validate_not_empty()]) location = StringField(required=False) class Meta: messages = { 'email_unique': 'This email has already been used, please use another or log in.' }
class SimpleValidator(Validator): name = StringField(validators=[ validate_not_empty(), validate_length(3, 99), validate_regexp('^[a-zA-Z ]*$') ]) email = StringField(validators=[validate_email()]) art_name = StringField( validators=[validate_not_empty(), validate_length(3, 99)]) art_price = DecimalField( validators=[validate_not_empty(), validate_range(1, 9999)]) availability = StringField(validators=[validate_one_of(['yes', 'no'])])
class FilmValidator(ModelValidator): title = StringField(validators=[validate_not_empty()], required=True) year = IntegerField(required=True) class Meta: messages = { 'title.empty': "\"Название\" не заполнено", 'year.coerce_int': "\"Год выхода\" не заполнено" }
class DriverForm(BaseForm): """DriverForm class for driver registration input validation. This class use the BaseForm class. Added field for registration number. :inherit: BaseForm """ reg_nr = StringField(required=True, max_length=40, validators=[validate_not_empty()])
def test_validate_not_empty(): validator = validate_not_empty() for value in ('', ' '): field.value = value with pytest.raises(ValidationError): validator(field, {}) for value in (None, 'alright', '123'): field.value = value validator(field, {})
class BaseForm(Validator): """BaseForm class for input validation. It makes sure that input fields are not empty and the email is a valid email. :inherit: Validator from peewee_validates""" first_name = StringField(required=True, max_length=40, validators=[validate_not_empty()]) last_name = StringField(required=True, max_length=40, validators=[validate_not_empty()]) username = StringField(required=True, max_length=40, validators=[validate_not_empty()]) email = StringField(required=True, max_length=40, validators=[validate_not_empty(), validate_email()]) password = StringField(required=True, max_length=40, validators=[validate_not_empty()])
class TestValidator(Validator): field1 = StringField(required=False, validators=[validate_not_empty()])