mirror of https://github.com/django/django.git
Fixed #30121 -- Fixed assertURLEqual() crash with reverse_lazy() URLs.
Regression in 24959e48d9
.
This commit is contained in:
parent
65858119d2
commit
d15c61cabb
|
@ -393,6 +393,7 @@ class SimpleTestCase(unittest.TestCase):
|
|||
"""
|
||||
def normalize(url):
|
||||
"""Sort the URL's query string parameters."""
|
||||
url = str(url) # Coerce reverse_lazy() URLs.
|
||||
scheme, netloc, path, params, query, fragment = urlparse(url)
|
||||
query_parts = sorted(parse_qsl(query))
|
||||
return urlunparse((scheme, netloc, path, params, urlencode(query_parts), fragment))
|
||||
|
|
|
@ -22,7 +22,7 @@ from django.test.utils import (
|
|||
CaptureQueriesContext, TestContextDecorator, isolate_apps,
|
||||
override_settings, setup_test_environment,
|
||||
)
|
||||
from django.urls import NoReverseMatch, path, reverse
|
||||
from django.urls import NoReverseMatch, path, reverse, reverse_lazy
|
||||
|
||||
from .models import Car, Person, PossessedCar
|
||||
from .views import empty_response
|
||||
|
@ -961,6 +961,7 @@ class AssertFieldOutputTests(SimpleTestCase):
|
|||
self.assertFieldOutput(MyCustomField, {}, {}, empty_value=None)
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='test_utils.urls')
|
||||
class AssertURLEqualTests(SimpleTestCase):
|
||||
def test_equal(self):
|
||||
valid_tests = (
|
||||
|
@ -971,6 +972,7 @@ class AssertURLEqualTests(SimpleTestCase):
|
|||
('http://example.com/?x=1&y=2&a=1&a=2', 'http://example.com/?a=1&a=2&y=2&x=1'),
|
||||
('/path/to/?x=1&y=2&z=3', '/path/to/?z=3&y=2&x=1'),
|
||||
('?x=1&y=2&z=3', '?z=3&y=2&x=1'),
|
||||
('/test_utils/no_template_used/', reverse_lazy('no_template_used')),
|
||||
)
|
||||
for url1, url2 in valid_tests:
|
||||
with self.subTest(url=url1):
|
||||
|
|
|
@ -4,5 +4,5 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path('test_utils/get_person/<int:pk>/', views.get_person),
|
||||
path('test_utils/no_template_used/', views.no_template_used),
|
||||
path('test_utils/no_template_used/', views.no_template_used, name='no_template_used'),
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue