def test_validate_email(): validator = validate_email() for value in ('bad', '())@asdfsd.com', 'tim@().com', [123, 123]): field.value = value with pytest.raises(ValidationError): validator(field, {'other': 'yes'}) for value in (None, '*****@*****.**', 'tim@localhost'): field.value = value validator(field, {'other': 'yes'})
class CustomValidator(ModelValidator): first_name = StringField(required=True) username = StringField(required=True) email = StringField(required=True, validators=[validate_email()]) password = StringField(required=True) class Meta: messages = { "email.validators": "Email address is invalid.", "required": "This field is required." }
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 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): email = StringField(validators=[validate_email()])
class CustomValidator(ModelValidator): email = StringField(required=True, validators=[validate_email()])
class CustomValidator(ModelValidator): name = StringField(required=True) email = StringField(required=True, validators=[validate_email()]) username = StringField(required=True) password = StringField(required=True)