Ticket #15229: 15229.patch

File 15229.patch, 2.1 KB (added by crayz_train, 14 years ago)

patch including tests for https, ftp, and ftps urls

  • django/core/validators.py

    diff --git a/django/core/validators.py b/django/core/validators.py
    index d6c4b28..a40af0c 100644
    a b class HeadRequest(urllib2.Request):  
    4545
    4646class URLValidator(RegexValidator):
    4747    regex = re.compile(
    48         r'^https?://' # http:// or https://
     48        r'^(?:http|ftp)s?://' # http:// or https://
    4949        r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
    5050        r'localhost|' #localhost...
    5151        r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
  • tests/modeltests/validation/tests.py

    diff --git a/tests/modeltests/validation/tests.py b/tests/modeltests/validation/tests.py
    index 142688f..cbd7cb8 100644
    a b class BaseModelValidationTests(ValidationTestCase):  
    6161        mtv = ModelToValidate(number=10, name='Some Name', url='http://www.djangoproject.com/')
    6262        self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection
    6363
     64    def test_correct_https_url_but_nonexisting(self):
     65        mtv = ModelToValidate(number=10, name='Some Name', url='https://www.djangoproject.com/')
     66        self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
     67
     68    def test_correct_ftp_url_but_nonexisting(self):
     69        mtv = ModelToValidate(number=10, name='Some Name', url='ftp://ftp.google.com/we-love-microsoft.html')
     70        self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
     71
     72    def test_correct_ftps_url_but_nonexisting(self):
     73        mtv = ModelToValidate(number=10, name='Some Name', url='ftps://ftp.google.com/we-love-microsoft.html')
     74        self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'This URL appears to be a broken link.'])
     75
    6476    def test_text_greater_that_charfields_max_length_raises_erros(self):
    6577        mtv = ModelToValidate(number=10, name='Some Name'*100)
    6678        self.assertFailsValidation(mtv.full_clean, ['name',])
Back to Top