Merge branch 'master' of https://github.com/shaunduncan/mongoengine
This commit is contained in:
commit
155d79ff4d
@ -149,6 +149,7 @@ class EmailField(StringField):
|
||||
def validate(self, value):
|
||||
if not EmailField.EMAIL_REGEX.match(value):
|
||||
self.error('Invalid Mail-address: %s' % value)
|
||||
super(EmailField, self).validate(value)
|
||||
|
||||
|
||||
class IntField(BaseField):
|
||||
|
@ -2299,6 +2299,18 @@ class FieldTest(unittest.TestCase):
|
||||
post.comments[1].content = 'here we go'
|
||||
post.validate()
|
||||
|
||||
def test_email_field_honors_regex(self):
|
||||
class User(Document):
|
||||
email = EmailField(regex=r'\w+@example.com')
|
||||
|
||||
# Fails regex validation
|
||||
user = User(email='me@foo.com')
|
||||
self.assertRaises(ValidationError, user.validate)
|
||||
|
||||
# Passes regex validation
|
||||
user = User(email='me@example.com')
|
||||
self.assertTrue(user.validate() is None)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user