summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorHonza Král <honza.kral@gmail.com>2009-08-15 13:34:21 +0000
committerHonza Král <honza.kral@gmail.com>2009-08-15 13:34:21 +0000
commit05524abf1beee11bb1efa1115eca345e0d96aa83 (patch)
tree35874c79fe2e40e426253a6355e4ad5993e83d49 /tests
parent5ebafe3fb98ca99c7b7392087b899f1053d5cf5e (diff)
[soc2009/model-validation] use validators in URLField model field
git-svn-id: http://code.djangoproject.com/svn/django/branches/soc2009/model-validation@11456 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/validation/models.py1
-rw-r--r--tests/modeltests/validation/tests.py12
2 files changed, 13 insertions, 0 deletions
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
index 6a08f083f1..1260417426 100644
--- a/tests/modeltests/validation/models.py
+++ b/tests/modeltests/validation/models.py
@@ -23,6 +23,7 @@ class ModelToValidate(models.Model):
number = models.IntegerField()
parent = models.ForeignKey('self', blank=True, null=True)
email = models.EmailField(blank=True)
+ url = models.URLField(blank=True)
f_with_custom_validator = models.IntegerField(blank=True, null=True, validators=[validate_answer_to_universe, ValidateFieldNotEqualsOtherField('number')])
def validate(self):
diff --git a/tests/modeltests/validation/tests.py b/tests/modeltests/validation/tests.py
index 4d2a71af35..25f9d0c005 100644
--- a/tests/modeltests/validation/tests.py
+++ b/tests/modeltests/validation/tests.py
@@ -39,6 +39,18 @@ class BaseModelValidationTests(ValidationTestCase):
mtv = ModelToValidate(number=10, name='Some Name', email='valid@email.com')
self.assertEqual(None, mtv.clean())
+ def test_wrong_url_value_raises_error(self):
+ mtv = ModelToValidate(number=10, name='Some Name', url='not a url')
+ self.assertFieldFailsValidationWithMessage(mtv.clean, 'url', [u'Enter a valid value.'])
+
+ def test_correct_url_but_nonexisting_gives_404(self):
+ mtv = ModelToValidate(number=10, name='Some Name', url='http://google.com/we-love-microsoft.html')
+ self.assertFieldFailsValidationWithMessage(mtv.clean, 'url', [u'This URL appears to be a broken link.'])
+
+ def test_correct_url_value_passes(self):
+ mtv = ModelToValidate(number=10, name='Some Name', url='http://www.djangoproject.com/')
+ self.assertEqual(None, mtv.clean()) # This will fail if there's no Internet connection
+
def test_text_greater_that_charfields_max_length_eaises_erros(self):
mtv = ModelToValidate(number=10, name='Some Name'*100)
self.assertFailsValidation(mtv.clean, ['name',])