Moved some email validation tests to validators tests
This commit is contained in:
parent
a8f888feb4
commit
8cb9968a91
|
@ -26,13 +26,22 @@ TEST_DATA = (
|
||||||
(validate_email, 'email@here.com', None),
|
(validate_email, 'email@here.com', None),
|
||||||
(validate_email, 'weirder-email@here.and.there.com', None),
|
(validate_email, 'weirder-email@here.and.there.com', None),
|
||||||
(validate_email, 'email@[127.0.0.1]', None),
|
(validate_email, 'email@[127.0.0.1]', None),
|
||||||
|
(validate_email, 'example@valid-----hyphens.com', None),
|
||||||
|
(validate_email, 'example@valid-with-hyphens.com', None),
|
||||||
|
|
||||||
(validate_email, None, ValidationError),
|
(validate_email, None, ValidationError),
|
||||||
(validate_email, '', ValidationError),
|
(validate_email, '', ValidationError),
|
||||||
(validate_email, 'abc', ValidationError),
|
(validate_email, 'abc', ValidationError),
|
||||||
|
(validate_email, 'abc@', ValidationError),
|
||||||
|
(validate_email, 'abc@bar', ValidationError),
|
||||||
(validate_email, 'a @x.cz', ValidationError),
|
(validate_email, 'a @x.cz', ValidationError),
|
||||||
|
(validate_email, 'abc@.com', ValidationError),
|
||||||
(validate_email, 'something@@somewhere.com', ValidationError),
|
(validate_email, 'something@@somewhere.com', ValidationError),
|
||||||
(validate_email, 'email@127.0.0.1', ValidationError),
|
(validate_email, 'email@127.0.0.1', ValidationError),
|
||||||
|
(validate_email, 'example@invalid-.com', ValidationError),
|
||||||
|
(validate_email, 'example@-invalid.com', ValidationError),
|
||||||
|
(validate_email, 'example@inv-.alid-.com', ValidationError),
|
||||||
|
(validate_email, 'example@inv-.-alid.com', ValidationError),
|
||||||
# Quoted-string format (CR not allowed)
|
# Quoted-string format (CR not allowed)
|
||||||
(validate_email, '"\\\011"@here.com', None),
|
(validate_email, '"\\\011"@here.com', None),
|
||||||
(validate_email, '"\\\012"@here.com', ValidationError),
|
(validate_email, '"\\\012"@here.com', ValidationError),
|
||||||
|
|
|
@ -501,6 +501,7 @@ class FieldsTests(SimpleTestCase):
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, 'abcd')
|
self.assertRaisesMessage(ValidationError, "'Enter a valid value.'", f.clean, 'abcd')
|
||||||
|
|
||||||
# EmailField ##################################################################
|
# EmailField ##################################################################
|
||||||
|
# See also modeltests/validators tests for validate_email specific tests
|
||||||
|
|
||||||
def test_emailfield_1(self):
|
def test_emailfield_1(self):
|
||||||
f = EmailField()
|
f = EmailField()
|
||||||
|
@ -508,16 +509,8 @@ class FieldsTests(SimpleTestCase):
|
||||||
self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, None)
|
self.assertRaisesMessage(ValidationError, "'This field is required.'", f.clean, None)
|
||||||
self.assertEqual('person@example.com', f.clean('person@example.com'))
|
self.assertEqual('person@example.com', f.clean('person@example.com'))
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'foo')
|
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'foo')
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'foo@')
|
self.assertEqual('local@domain.with.idn.xyz\xe4\xf6\xfc\xdfabc.part.com',
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'foo@bar')
|
f.clean('local@domain.with.idn.xyzäöüßabc.part.com'))
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'example@invalid-.com')
|
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'example@-invalid.com')
|
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'example@inv-.alid-.com')
|
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'example@inv-.-alid.com')
|
|
||||||
self.assertEqual('example@valid-----hyphens.com', f.clean('example@valid-----hyphens.com'))
|
|
||||||
self.assertEqual('example@valid-with-hyphens.com', f.clean('example@valid-with-hyphens.com'))
|
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'example@.com')
|
|
||||||
self.assertEqual('local@domain.with.idn.xyz\xe4\xf6\xfc\xdfabc.part.com', f.clean('local@domain.with.idn.xyzäöüßabc.part.com'))
|
|
||||||
|
|
||||||
def test_email_regexp_for_performance(self):
|
def test_email_regexp_for_performance(self):
|
||||||
f = EmailField()
|
f = EmailField()
|
||||||
|
@ -530,17 +523,15 @@ class FieldsTests(SimpleTestCase):
|
||||||
'viewx3dtextx26qx3d@yahoo.comx26latlngx3d15854521645943074058'
|
'viewx3dtextx26qx3d@yahoo.comx26latlngx3d15854521645943074058'
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_emailfield_2(self):
|
def test_emailfield_not_required(self):
|
||||||
f = EmailField(required=False)
|
f = EmailField(required=False)
|
||||||
self.assertEqual('', f.clean(''))
|
self.assertEqual('', f.clean(''))
|
||||||
self.assertEqual('', f.clean(None))
|
self.assertEqual('', f.clean(None))
|
||||||
self.assertEqual('person@example.com', f.clean('person@example.com'))
|
self.assertEqual('person@example.com', f.clean('person@example.com'))
|
||||||
self.assertEqual('example@example.com', f.clean(' example@example.com \t \t '))
|
self.assertEqual('example@example.com', f.clean(' example@example.com \t \t '))
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'foo')
|
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'foo')
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'foo@')
|
|
||||||
self.assertRaisesMessage(ValidationError, "'Enter a valid email address.'", f.clean, 'foo@bar')
|
|
||||||
|
|
||||||
def test_emailfield_3(self):
|
def test_emailfield_min_max_length(self):
|
||||||
f = EmailField(min_length=10, max_length=15)
|
f = EmailField(min_length=10, max_length=15)
|
||||||
self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'", f.clean, 'a@foo.com')
|
self.assertRaisesMessage(ValidationError, "'Ensure this value has at least 10 characters (it has 9).'", f.clean, 'a@foo.com')
|
||||||
self.assertEqual('alf@foo.com', f.clean('alf@foo.com'))
|
self.assertEqual('alf@foo.com', f.clean('alf@foo.com'))
|
||||||
|
|
Loading…
Reference in New Issue