diff options
| author | Jake Howard <RealOrangeOne@users.noreply.github.com> | 2024-05-29 14:48:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-29 10:48:27 -0300 |
| commit | ff308a06047cd60806d604a7cf612e5656ee2ac9 (patch) | |
| tree | f2139fbf020cbdf33bad64a3377700623c18a44f /tests | |
| parent | 02dab94c7b8585c7ae3854465574d768e1df75d3 (diff) | |
Fixed 35467 -- Replaced urlparse with urlsplit where appropriate.
This work should not generate any change of functionality, and
`urlsplit` is approximately 6x faster.
Most use cases of `urlparse` didn't touch the path, so they can be
converted to `urlsplit` without any issue. Most of those which do use
`.path`, simply parse the URL, mutate the querystring, then put them
back together, which is also fine (so long as urlunsplit is used).
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_views/tests.py | 10 | ||||
| -rw-r--r-- | tests/csrf_tests/tests.py | 16 |
2 files changed, 11 insertions, 15 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index d49e7d028b..cb6815e7a8 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -4,7 +4,7 @@ import re import unittest import zoneinfo from unittest import mock -from urllib.parse import parse_qsl, urljoin, urlparse +from urllib.parse import parse_qsl, urljoin, urlsplit from django import forms from django.contrib import admin @@ -357,7 +357,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase): **save_option, }, ) - parsed_url = urlparse(response.url) + parsed_url = urlsplit(response.url) self.assertEqual(parsed_url.query, qsl) def test_change_query_string_persists(self): @@ -386,7 +386,7 @@ class AdminViewBasicTest(AdminViewBasicTestCase): **save_option, }, ) - parsed_url = urlparse(response.url) + parsed_url = urlsplit(response.url) self.assertEqual(parsed_url.query, qsl) def test_basic_edit_GET(self): @@ -8032,11 +8032,11 @@ class AdminKeepChangeListFiltersTests(TestCase): Assert that two URLs are equal despite the ordering of their querystring. Refs #22360. """ - parsed_url1 = urlparse(url1) + parsed_url1 = urlsplit(url1) path1 = parsed_url1.path parsed_qs1 = dict(parse_qsl(parsed_url1.query)) - parsed_url2 = urlparse(url2) + parsed_url2 = urlsplit(url2) path2 = parsed_url2.path parsed_qs2 = dict(parse_qsl(parsed_url2.query)) diff --git a/tests/csrf_tests/tests.py b/tests/csrf_tests/tests.py index 9407221cd1..b736276534 100644 --- a/tests/csrf_tests/tests.py +++ b/tests/csrf_tests/tests.py @@ -709,25 +709,21 @@ class CsrfViewMiddlewareTestMixin(CsrfFunctionTestMixin): response = mw.process_view(req, post_form_view, (), {}) self.assertContains(response, malformed_referer_msg, status_code=403) # missing scheme - # >>> urlparse('//example.com/') - # ParseResult( - # scheme='', netloc='example.com', path='/', params='', query='', fragment='', - # ) + # >>> urlsplit('//example.com/') + # SplitResult(scheme='', netloc='example.com', path='/', query='', fragment='') req.META["HTTP_REFERER"] = "//example.com/" self._check_referer_rejects(mw, req) response = mw.process_view(req, post_form_view, (), {}) self.assertContains(response, malformed_referer_msg, status_code=403) # missing netloc - # >>> urlparse('https://') - # ParseResult( - # scheme='https', netloc='', path='', params='', query='', fragment='', - # ) + # >>> urlsplit('https://') + # SplitResult(scheme='https', netloc='', path='', query='', fragment='') req.META["HTTP_REFERER"] = "https://" self._check_referer_rejects(mw, req) response = mw.process_view(req, post_form_view, (), {}) self.assertContains(response, malformed_referer_msg, status_code=403) # Invalid URL - # >>> urlparse('https://[') + # >>> urlsplit('https://[') # ValueError: Invalid IPv6 URL req.META["HTTP_REFERER"] = "https://[" self._check_referer_rejects(mw, req) @@ -979,7 +975,7 @@ class CsrfViewMiddlewareTestMixin(CsrfFunctionTestMixin): @override_settings(ALLOWED_HOSTS=["www.example.com"]) def test_bad_origin_cannot_be_parsed(self): """ - A POST request with an origin that can't be parsed by urlparse() is + A POST request with an origin that can't be parsed by urlsplit() is rejected. """ req = self._get_POST_request_with_token() |
