diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-03-31 13:55:03 +0000 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2012-03-31 13:55:03 +0000 |
| commit | 9ed6e08ff99c18710c0e4875f827235f04c89d76 (patch) | |
| tree | 1781a682463d7c6eb60e39408d8788c2ca3d2fce /tests | |
| parent | 800e3941c50139347ab48e6d6731d445875357ed (diff) | |
Removed deprecated URLField.verify_exists.
The deprecation schedule was slightly accelerated because of possible security ramifications.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17847 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/modeltests/validation/models.py | 3 | ||||
| -rw-r--r-- | tests/modeltests/validation/tests.py | 32 | ||||
| -rw-r--r-- | tests/regressiontests/forms/tests/error_messages.py | 7 | ||||
| -rw-r--r-- | tests/regressiontests/forms/tests/fields.py | 61 | ||||
| -rw-r--r-- | tests/regressiontests/generic_inline_admin/models.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/model_forms_regress/models.py | 2 |
6 files changed, 5 insertions, 102 deletions
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py index 8010701823..e402162b9a 100644 --- a/tests/modeltests/validation/models.py +++ b/tests/modeltests/validation/models.py @@ -15,7 +15,6 @@ class ModelToValidate(models.Model): parent = models.ForeignKey('self', blank=True, null=True, limit_choices_to={'number': 10}) email = models.EmailField(blank=True) url = models.URLField(blank=True) - url_verify = models.URLField(blank=True, verify_exists=True) f_with_custom_validator = models.IntegerField(blank=True, null=True, validators=[validate_answer_to_universe]) def clean(self): @@ -102,4 +101,4 @@ try: auto2 = models.AutoField(primary_key=True) except AssertionError, assertion_error: pass # Fail silently -assert str(assertion_error) == u"A model can't have more than one AutoField."
\ No newline at end of file +assert str(assertion_error) == u"A model can't have more than one AutoField." diff --git a/tests/modeltests/validation/tests.py b/tests/modeltests/validation/tests.py index 5c94f439d1..f255498306 100644 --- a/tests/modeltests/validation/tests.py +++ b/tests/modeltests/validation/tests.py @@ -1,14 +1,9 @@ from __future__ import absolute_import -import warnings - from django import forms from django.core.exceptions import NON_FIELD_ERRORS from django.test import TestCase -# Import the verify_exists_urls from the 'forms' test app -from regressiontests.forms.tests.fields import verify_exists_urls - from . import ValidationTestCase from .models import (Author, Article, ModelToValidate, GenericIPAddressTestModel, GenericIPAddrUnpackUniqueTest) @@ -22,14 +17,6 @@ from .validators import TestModelsWithValidators class BaseModelValidationTests(ValidationTestCase): - def setUp(self): - self.save_warnings_state() - warnings.filterwarnings('ignore', category=DeprecationWarning, - module='django.core.validators') - - def tearDown(self): - self.restore_warnings_state() - def test_missing_required_field_raises_error(self): mtv = ModelToValidate(f_with_custom_validator=42) self.assertFailsValidation(mtv.full_clean, ['name', 'number']) @@ -70,25 +57,6 @@ class BaseModelValidationTests(ValidationTestCase): mtv = ModelToValidate(number=10, name='Some Name', url='not a url') self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url', [u'Enter a valid value.']) - #The tests below which use url_verify are deprecated - def test_correct_url_but_nonexisting_gives_404(self): - mtv = ModelToValidate(number=10, name='Some Name', url_verify='http://qa-dev.w3.org/link-testsuite/http.php?code=404') - self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url_verify', [u'This URL appears to be a broken link.']) - - @verify_exists_urls(existing_urls=('http://www.google.com/',)) - def test_correct_url_value_passes(self): - mtv = ModelToValidate(number=10, name='Some Name', url_verify='http://www.google.com/') - self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection - - @verify_exists_urls(existing_urls=('http://qa-dev.w3.org/link-testsuite/http.php?code=301',)) - def test_correct_url_with_redirect(self): - mtv = ModelToValidate(number=10, name='Some Name', url_verify='http://qa-dev.w3.org/link-testsuite/http.php?code=301') #example.com is a redirect to iana.org now - self.assertEqual(None, mtv.full_clean()) # This will fail if there's no Internet connection - - def test_correct_https_url_but_nonexisting(self): - mtv = ModelToValidate(number=10, name='Some Name', url_verify='https://www.example.com/') - self.assertFieldFailsValidationWithMessage(mtv.full_clean, 'url_verify', [u'This URL appears to be a broken link.']) - def test_text_greater_that_charfields_max_length_raises_erros(self): mtv = ModelToValidate(number=10, name='Some Name'*100) self.assertFailsValidation(mtv.full_clean, ['name',]) diff --git a/tests/regressiontests/forms/tests/error_messages.py b/tests/regressiontests/forms/tests/error_messages.py index b7b4e986b3..973bf22ab1 100644 --- a/tests/regressiontests/forms/tests/error_messages.py +++ b/tests/regressiontests/forms/tests/error_messages.py @@ -7,8 +7,6 @@ from django.forms import * from django.test import TestCase from django.utils.safestring import mark_safe -from .fields import verify_exists_urls - class AssertFormErrorsMixin(object): def assertFormErrors(self, expected, the_callable, *args, **kwargs): @@ -143,17 +141,14 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin): self.assertFormErrors([u'EMPTY FILE'], f.clean, SimpleUploadedFile('name', None)) self.assertFormErrors([u'EMPTY FILE'], f.clean, SimpleUploadedFile('name', '')) - @verify_exists_urls() def test_urlfield(self): e = { 'required': 'REQUIRED', 'invalid': 'INVALID', - 'invalid_link': 'INVALID LINK', } - f = URLField(verify_exists=True, error_messages=e) + f = URLField(error_messages=e) self.assertFormErrors([u'REQUIRED'], f.clean, '') self.assertFormErrors([u'INVALID'], f.clean, 'abc.c') - self.assertFormErrors([u'INVALID LINK'], f.clean, 'http://www.broken.djangoproject.com') def test_booleanfield(self): e = { diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py index 03e0ff65a3..3820bb9858 100644 --- a/tests/regressiontests/forms/tests/fields.py +++ b/tests/regressiontests/forms/tests/fields.py @@ -27,10 +27,8 @@ __init__(). For example, CharField has a max_length option. import datetime import re import os -import urllib2 import warnings from decimal import Decimal -from functools import wraps from django.core.files.uploadedfile import SimpleUploadedFile from django.forms import * @@ -48,32 +46,6 @@ def fix_os_paths(x): return x -def verify_exists_urls(existing_urls=()): - """ - Patches urllib to simulate the availability of some urls even when there - is no Internet connection. This hack should be removed alongside with - `URLField.verify_exists` in Django 1.5. - """ - def decorator(func): - @wraps(func) - def wrapper(*args, **kwargs): - from django.core import validators - # patch urllib2.OpenerDirector - original_open = validators.urllib2.OpenerDirector.open - def custom_open(self, req, data=None, timeout=None): - if req.get_full_url() in existing_urls: - return True - raise Exception() - try: - urllib2.OpenerDirector.open = custom_open - func(*args, **kwargs) - finally: - # unpatch urllib2.OpenerDirector - validators.urllib2.OpenerDirector.open = original_open - return wrapper - return decorator - - class FieldsTests(SimpleTestCase): def setUp(self): @@ -651,30 +623,6 @@ class FieldsTests(SimpleTestCase): self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example.') self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://.com') - @verify_exists_urls(('http://www.google.com/',)) - def test_urlfield_3(self): - f = URLField(verify_exists=True) - self.assertEqual(u'http://www.google.com/', f.clean('http://www.google.com')) - self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 'http://example') - self.assertRaises(ValidationError, f.clean, 'http://www.broken.djangoproject.com') # bad domain - self.assertRaises(ValidationError, f.clean, 'http://qa-dev.w3.org/link-testsuite/http.php?code=405') # Method not allowed - try: - f.clean('http://www.broken.djangoproject.com') # bad domain - except ValidationError, e: - self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) - self.assertRaises(ValidationError, f.clean, 'http://qa-dev.w3.org/link-testsuite/http.php?code=400') # good domain, bad page - try: - f.clean('http://google.com/we-love-microsoft.html') # good domain, bad page - except ValidationError, e: - self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) - - @verify_exists_urls(('http://www.google.com/',)) - def test_urlfield_4(self): - f = URLField(verify_exists=True, required=False) - self.assertEqual(u'', f.clean('')) - self.assertEqual(u'http://www.google.com/', f.clean('http://www.google.com')) - - @verify_exists_urls(('http://example.com/',)) def test_urlfield_5(self): f = URLField(min_length=15, max_length=20) self.assertRaisesMessage(ValidationError, "[u'Ensure this value has at least 15 characters (it has 13).']", f.clean, 'http://f.com') @@ -698,7 +646,7 @@ class FieldsTests(SimpleTestCase): self.assertEqual(u'http://example.com/?some_param=some_value', f.clean('http://example.com?some_param=some_value')) def test_urlfield_9(self): - f = URLField(verify_exists=False) + f = URLField() urls = ( u'http://עברית.idn.icann.org/', u'http://sãopaulo.com/', @@ -722,13 +670,6 @@ class FieldsTests(SimpleTestCase): except ValidationError, e: self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) - @verify_exists_urls((u'http://xn--hxargifdar.idn.icann.org/%CE%91%CF%81%CF%87%CE%B9%CE%BA%CE%AE_%CF%83%CE%B5%CE%BB%CE%AF%CE%B4%CE%B1',)) - def test_urlfield_10(self): - # UTF-8 in the domain. - f = URLField(verify_exists=True) - url = u'http://\u03b5\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac.idn.icann.org/\u0391\u03c1\u03c7\u03b9\u03ba\u03ae_\u03c3\u03b5\u03bb\u03af\u03b4\u03b1' - self.assertEqual(url, f.clean(url)) - def test_urlfield_not_string(self): f = URLField(required=False) self.assertRaisesMessage(ValidationError, "[u'Enter a valid URL.']", f.clean, 23) diff --git a/tests/regressiontests/generic_inline_admin/models.py b/tests/regressiontests/generic_inline_admin/models.py index b9426b4f2a..a1555666b3 100644 --- a/tests/regressiontests/generic_inline_admin/models.py +++ b/tests/regressiontests/generic_inline_admin/models.py @@ -16,7 +16,7 @@ class Media(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey() - url = models.URLField(verify_exists=False) + url = models.URLField() description = models.CharField(max_length=100, blank=True) keywords = models.CharField(max_length=100, blank=True) diff --git a/tests/regressiontests/model_forms_regress/models.py b/tests/regressiontests/model_forms_regress/models.py index cdf324164d..d070a9be75 100644 --- a/tests/regressiontests/model_forms_regress/models.py +++ b/tests/regressiontests/model_forms_regress/models.py @@ -57,7 +57,7 @@ class Author1(models.Model): full_name = models.CharField(max_length=255) class Homepage(models.Model): - url = models.URLField(verify_exists=False) + url = models.URLField() class Document(models.Model): myfile = models.FileField(upload_to='unused', blank=True) |
