summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-01-21 06:31:33 -0800
committerTim Graham <timograham@gmail.com>2019-01-21 09:31:45 -0500
commit28fb4ed5d9fe541df6b2b0e93952c62bf0ce7962 (patch)
treed680a7e84c248f380e7918bc09cb4297d562c313
parent6516e49262546238d02f6ca37b74ee0e67dead0a (diff)
[2.2.x] Fixed #30121 -- Fixed assertURLEqual() crash with reverse_lazy() URLs.
Regression in 24959e48d949a20be969f649ece3576dbc7ce422. Backport of d15c61cabbe1c15068ffeb58c64035057f0c7d5c from master.
-rw-r--r--django/test/testcases.py1
-rw-r--r--tests/test_utils/tests.py4
-rw-r--r--tests/test_utils/urls.py2
3 files changed, 5 insertions, 2 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py
index 3dd14a08c0..991165c04d 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -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))
diff --git a/tests/test_utils/tests.py b/tests/test_utils/tests.py
index 3a315e7c10..a1a113a26e 100644
--- a/tests/test_utils/tests.py
+++ b/tests/test_utils/tests.py
@@ -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):
diff --git a/tests/test_utils/urls.py b/tests/test_utils/urls.py
index 5cfab5d831..6b060dff95 100644
--- a/tests/test_utils/urls.py
+++ b/tests/test_utils/urls.py
@@ -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'),
]