class TestEmailValidator(unittest.TestCase): def setUp(self): self.validator = EmailValidator() def test_valid_emails(self): valid_emails = [ '[email protected]', '"Abc\@def"@example.com', '"Fred Bloggs"@example.com', '"Joe\\Blow"@example.com', '"Abc@def"@example.com', 'customer/[email protected]', '\[email protected]', '!def!xyz%[email protected]', '*****@*****.**', '*****@*****.**', 'mimimi@президент.рф' ] for email in valid_emails: assert self.validator.validate(email) def test_invalid_emails(self): invalid_emails = ['email.r', '&&&abir@valg'] for email in invalid_emails: assert not self.validator.validate(email)
def setUp(self): self.validator = EmailValidator()
class TD(BaseDoc): field1 = StringField(validators=[EmailValidator()])