1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Refs #34380 -- Changed the URLField default scheme to https and removed FORMS_URLFIELD_ASSUME_HTTPS per deprecation timeline.

This commit is contained in:
Sarah Boyce
2024-12-12 17:39:58 +01:00
parent 9cb1ffa67b
commit 9a3f86e960
13 changed files with 19 additions and 197 deletions

View File

@@ -22,10 +22,9 @@ from django.forms.models import (
modelform_factory,
)
from django.template import Context, Template
from django.test import SimpleTestCase, TestCase, ignore_warnings, skipUnlessDBFeature
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
from django.test.utils import isolate_apps
from django.utils.choices import BlankChoiceIterator
from django.utils.deprecation import RemovedInDjango60Warning
from django.utils.version import PY314, PYPY
from .models import (
@@ -374,7 +373,6 @@ class ModelFormBaseTest(TestCase):
obj = form.save()
self.assertEqual(obj.name, "")
@ignore_warnings(category=RemovedInDjango60Warning)
def test_save_blank_null_unique_charfield_saves_null(self):
form_class = modelform_factory(
model=NullableUniqueCharFieldModel, fields="__all__"
@@ -913,13 +911,6 @@ class ModelFormBaseTest(TestCase):
self.assertEqual(m2.date_published, datetime.date(2010, 1, 1))
# RemovedInDjango60Warning.
# It's a temporary workaround for the deprecation period.
class HttpsURLField(forms.URLField):
def __init__(self, **kwargs):
super().__init__(assume_scheme="https", **kwargs)
class FieldOverridesByFormMetaForm(forms.ModelForm):
class Meta:
model = Category
@@ -943,7 +934,7 @@ class FieldOverridesByFormMetaForm(forms.ModelForm):
}
}
field_classes = {
"url": HttpsURLField,
"url": forms.URLField,
}
@@ -2918,7 +2909,6 @@ class ModelOtherFieldTests(SimpleTestCase):
},
)
@ignore_warnings(category=RemovedInDjango60Warning)
def test_url_on_modelform(self):
"Check basic URL field validation on model forms"
@@ -2943,32 +2933,6 @@ class ModelOtherFieldTests(SimpleTestCase):
)
self.assertTrue(HomepageForm({"url": "http://example.com/foo/bar"}).is_valid())
def test_url_modelform_assume_scheme_warning(self):
msg = (
"The default scheme will be changed from 'http' to 'https' in Django "
"6.0. Pass the forms.URLField.assume_scheme argument to silence this "
"warning, or set the FORMS_URLFIELD_ASSUME_HTTPS transitional setting to "
"True to opt into using 'https' as the new default scheme."
)
with self.assertWarnsMessage(RemovedInDjango60Warning, msg):
class HomepageForm(forms.ModelForm):
class Meta:
model = Homepage
fields = "__all__"
def test_url_modelform_assume_scheme_early_adopt_https(self):
msg = "The FORMS_URLFIELD_ASSUME_HTTPS transitional setting is deprecated."
with (
self.assertWarnsMessage(RemovedInDjango60Warning, msg),
self.settings(FORMS_URLFIELD_ASSUME_HTTPS=True),
):
class HomepageForm(forms.ModelForm):
class Meta:
model = Homepage
fields = "__all__"
def test_modelform_non_editable_field(self):
"""
When explicitly including a non-editable field in a ModelForm, the
@@ -2995,9 +2959,6 @@ class ModelOtherFieldTests(SimpleTestCase):
"""
class HomepageForm(forms.ModelForm):
# RemovedInDjango60Warning.
url = forms.URLField(assume_scheme="https")
class Meta:
model = Homepage
fields = "__all__"