diff options
| author | Claude Paroz <claude@2xlibre.net> | 2017-01-26 14:25:15 +0100 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2017-01-26 19:49:03 +0100 |
| commit | fee42fd99ee470528858c2ccb3621135c30ec262 (patch) | |
| tree | b7d0905a11f28a0b554d39b30e0286dca2a07cc1 /tests | |
| parent | af598187ecd9ddf398aa7a68a2b955599ddf3ae1 (diff) | |
Refs #23919 -- Replaced usage of django.utils.http utilities with Python equivalents
Thanks Tim Graham for the review.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auth_tests/test_views.py | 21 | ||||
| -rw-r--r-- | tests/contenttypes_tests/models.py | 7 | ||||
| -rw-r--r-- | tests/file_uploads/tests.py | 6 | ||||
| -rw-r--r-- | tests/requests/tests.py | 6 | ||||
| -rw-r--r-- | tests/servers/tests.py | 2 | ||||
| -rw-r--r-- | tests/utils_tests/test_encoding.py | 4 |
6 files changed, 23 insertions, 23 deletions
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py index 76d167fa40..cee3383f05 100644 --- a/tests/auth_tests/test_views.py +++ b/tests/auth_tests/test_views.py @@ -3,7 +3,7 @@ import itertools import os import re from importlib import import_module -from urllib.parse import ParseResult, urlparse +from urllib.parse import ParseResult, quote, urlparse from django.apps import apps from django.conf import settings @@ -28,7 +28,6 @@ from django.test.utils import patch_logger from django.urls import NoReverseMatch, reverse, reverse_lazy from django.utils.deprecation import RemovedInDjango21Warning from django.utils.encoding import force_text -from django.utils.http import urlquote from django.utils.translation import LANGUAGE_SESSION_KEY from .client import PasswordResetConfirmClient @@ -546,7 +545,7 @@ class LoginTest(AuthViewsTestCase): nasty_url = '%(url)s?%(next)s=%(bad_url)s' % { 'url': login_url, 'next': REDIRECT_FIELD_NAME, - 'bad_url': urlquote(bad_url), + 'bad_url': quote(bad_url), } response = self.client.post(nasty_url, { 'username': 'testclient', @@ -568,7 +567,7 @@ class LoginTest(AuthViewsTestCase): safe_url = '%(url)s?%(next)s=%(good_url)s' % { 'url': login_url, 'next': REDIRECT_FIELD_NAME, - 'good_url': urlquote(good_url), + 'good_url': quote(good_url), } response = self.client.post(safe_url, { 'username': 'testclient', @@ -583,7 +582,7 @@ class LoginTest(AuthViewsTestCase): not_secured_url = '%(url)s?%(next)s=%(next_url)s' % { 'url': login_url, 'next': REDIRECT_FIELD_NAME, - 'next_url': urlquote(non_https_next_url), + 'next_url': quote(non_https_next_url), } post_data = { 'username': 'testclient', @@ -701,13 +700,13 @@ class LoginURLSettings(AuthViewsTestCase): @override_settings(LOGIN_URL='http://remote.example.com/login') def test_remote_login_url(self): - quoted_next = urlquote('http://testserver/login_required/') + quoted_next = quote('http://testserver/login_required/') expected = 'http://remote.example.com/login?next=%s' % quoted_next self.assertLoginURLEquals(expected) @override_settings(LOGIN_URL='https:///login/') def test_https_login_url(self): - quoted_next = urlquote('http://testserver/login_required/') + quoted_next = quote('http://testserver/login_required/') expected = 'https:///login/?next=%s' % quoted_next self.assertLoginURLEquals(expected) @@ -717,7 +716,7 @@ class LoginURLSettings(AuthViewsTestCase): @override_settings(LOGIN_URL='http://remote.example.com/login/?next=/default/') def test_remote_login_url_with_next_querystring(self): - quoted_next = urlquote('http://testserver/login_required/') + quoted_next = quote('http://testserver/login_required/') expected = 'http://remote.example.com/login/?next=%s' % quoted_next self.assertLoginURLEquals(expected) @@ -973,7 +972,7 @@ class LogoutTest(AuthViewsTestCase): nasty_url = '%(url)s?%(next)s=%(bad_url)s' % { 'url': logout_url, 'next': REDIRECT_FIELD_NAME, - 'bad_url': urlquote(bad_url), + 'bad_url': quote(bad_url), } self.login() response = self.client.get(nasty_url) @@ -994,7 +993,7 @@ class LogoutTest(AuthViewsTestCase): safe_url = '%(url)s?%(next)s=%(good_url)s' % { 'url': logout_url, 'next': REDIRECT_FIELD_NAME, - 'good_url': urlquote(good_url), + 'good_url': quote(good_url), } self.login() response = self.client.get(safe_url) @@ -1008,7 +1007,7 @@ class LogoutTest(AuthViewsTestCase): url = '%(url)s?%(next)s=%(next_url)s' % { 'url': logout_url, 'next': REDIRECT_FIELD_NAME, - 'next_url': urlquote(non_https_next_url), + 'next_url': quote(non_https_next_url), } self.login() response = self.client.get(url, secure=True) diff --git a/tests/contenttypes_tests/models.py b/tests/contenttypes_tests/models.py index 0aa8bbf0bc..5475c4aade 100644 --- a/tests/contenttypes_tests/models.py +++ b/tests/contenttypes_tests/models.py @@ -1,10 +1,11 @@ +from urllib.parse import quote + from django.contrib.contenttypes.fields import ( GenericForeignKey, GenericRelation, ) from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import SiteManager from django.db import models -from django.utils.http import urlquote class Site(models.Model): @@ -72,7 +73,7 @@ class FooWithUrl(FooWithoutUrl): """ def get_absolute_url(self): - return "/users/%s/" % urlquote(self.name) + return "/users/%s/" % quote(self.name) class FooWithBrokenAbsoluteUrl(FooWithoutUrl): @@ -126,4 +127,4 @@ class ModelWithNullFKToSite(models.Model): return self.title def get_absolute_url(self): - return '/title/%s/' % urlquote(self.title) + return '/title/%s/' % quote(self.title) diff --git a/tests/file_uploads/tests.py b/tests/file_uploads/tests.py index 44a7272753..51e6937598 100644 --- a/tests/file_uploads/tests.py +++ b/tests/file_uploads/tests.py @@ -7,13 +7,13 @@ import sys import tempfile as sys_tempfile import unittest from io import BytesIO, StringIO +from urllib.parse import quote from django.core.files import temp as tempfile from django.core.files.uploadedfile import SimpleUploadedFile from django.http.multipartparser import MultiPartParser, parse_header from django.test import SimpleTestCase, TestCase, client, override_settings from django.utils.encoding import force_bytes -from django.utils.http import urlquote from . import uploadhandler from .models import FileModel @@ -127,7 +127,7 @@ class FileUploadTests(TestCase): payload = client.FakePayload() payload.write('\r\n'.join([ '--' + client.BOUNDARY, - 'Content-Disposition: form-data; name="file_unicode"; filename*=UTF-8\'\'%s' % urlquote(UNICODE_FILENAME), + 'Content-Disposition: form-data; name="file_unicode"; filename*=UTF-8\'\'%s' % quote(UNICODE_FILENAME), 'Content-Type: application/octet-stream', '', 'You got pwnd.\r\n', @@ -153,7 +153,7 @@ class FileUploadTests(TestCase): payload.write( '\r\n'.join([ '--' + client.BOUNDARY, - 'Content-Disposition: form-data; name*=UTF-8\'\'file_unicode; filename*=UTF-8\'\'%s' % urlquote( + 'Content-Disposition: form-data; name*=UTF-8\'\'file_unicode; filename*=UTF-8\'\'%s' % quote( UNICODE_FILENAME ), 'Content-Type: application/octet-stream', diff --git a/tests/requests/tests.py b/tests/requests/tests.py index ac331232aa..932078fb0e 100644 --- a/tests/requests/tests.py +++ b/tests/requests/tests.py @@ -3,7 +3,7 @@ from datetime import datetime, timedelta from http import cookies from io import BytesIO from itertools import chain -from urllib.parse import urlencode as original_urlencode +from urllib.parse import urlencode from django.core.exceptions import SuspiciousOperation from django.core.handlers.wsgi import LimitedStream, WSGIRequest @@ -14,7 +14,7 @@ from django.http.request import split_domain_port from django.test import RequestFactory, SimpleTestCase, override_settings from django.test.client import FakePayload from django.test.utils import freeze_time -from django.utils.http import cookie_date, urlencode +from django.utils.http import cookie_date from django.utils.timezone import utc @@ -379,7 +379,7 @@ class RequestsTests(SimpleTestCase): """ Test a POST with non-utf-8 payload encoding. """ - payload = FakePayload(original_urlencode({'key': 'España'.encode('latin-1')})) + payload = FakePayload(urlencode({'key': 'España'.encode('latin-1')})) request = WSGIRequest({ 'REQUEST_METHOD': 'POST', 'CONTENT_LENGTH': len(payload), diff --git a/tests/servers/tests.py b/tests/servers/tests.py index 27f7f9994f..5052f57908 100644 --- a/tests/servers/tests.py +++ b/tests/servers/tests.py @@ -5,10 +5,10 @@ import errno import os import socket from urllib.error import HTTPError +from urllib.parse import urlencode from urllib.request import urlopen from django.test import LiveServerTestCase, override_settings -from django.utils.http import urlencode from .models import Person diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py index 2efdd24ff8..ea3b97ddf5 100644 --- a/tests/utils_tests/test_encoding.py +++ b/tests/utils_tests/test_encoding.py @@ -1,12 +1,12 @@ import datetime import unittest +from urllib.parse import quote_plus from django.utils.encoding import ( escape_uri_path, filepath_to_uri, force_bytes, force_text, iri_to_uri, smart_text, uri_to_iri, ) from django.utils.functional import SimpleLazyObject -from django.utils.http import urlquote_plus class TestEncodingUtils(unittest.TestCase): @@ -72,7 +72,7 @@ class TestRFC3987IEncodingUtils(unittest.TestCase): # Valid UTF-8 sequences are encoded. ('red%09rosé#red', 'red%09ros%C3%A9#red'), ('/blog/for/Jürgen Münster/', '/blog/for/J%C3%BCrgen%20M%C3%BCnster/'), - ('locations/%s' % urlquote_plus('Paris & Orléans'), 'locations/Paris+%26+Orl%C3%A9ans'), + ('locations/%s' % quote_plus('Paris & Orléans'), 'locations/Paris+%26+Orl%C3%A9ans'), # Reserved chars remain unescaped. ('%&', '%&'), |
