Refs #27795 -- Removed force_bytes/text() usage in tests.
This commit is contained in:
parent
b38532cd6b
commit
fa75b2cb51
|
@ -8,7 +8,6 @@ from django.contrib.contenttypes.models import ContentType
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
from django.utils.encoding import force_bytes
|
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
|
|
||||||
from .models import Article, ArticleProxy, Site
|
from .models import Article, ArticleProxy, Site
|
||||||
|
@ -211,9 +210,10 @@ class LogEntryTests(TestCase):
|
||||||
logentry.content_type = None
|
logentry.content_type = None
|
||||||
logentry.save()
|
logentry.save()
|
||||||
|
|
||||||
counted_presence_before = response.content.count(force_bytes(should_contain))
|
should_contain = should_contain.encode()
|
||||||
|
counted_presence_before = response.content.count(should_contain)
|
||||||
response = self.client.get(reverse('admin:index'))
|
response = self.client.get(reverse('admin:index'))
|
||||||
counted_presence_after = response.content.count(force_bytes(should_contain))
|
counted_presence_after = response.content.count(should_contain)
|
||||||
self.assertEqual(counted_presence_before - 1, counted_presence_after)
|
self.assertEqual(counted_presence_before - 1, counted_presence_after)
|
||||||
|
|
||||||
def test_proxy_model_content_type_is_used_for_log_entries(self):
|
def test_proxy_model_content_type_is_used_for_log_entries(self):
|
||||||
|
|
|
@ -29,7 +29,7 @@ from django.test.utils import override_script_prefix, patch_logger
|
||||||
from django.urls import NoReverseMatch, resolve, reverse
|
from django.urls import NoReverseMatch, resolve, reverse
|
||||||
from django.utils import formats, translation
|
from django.utils import formats, translation
|
||||||
from django.utils.cache import get_max_age
|
from django.utils.cache import get_max_age
|
||||||
from django.utils.encoding import force_bytes, force_text, iri_to_uri
|
from django.utils.encoding import iri_to_uri
|
||||||
from django.utils.html import escape
|
from django.utils.html import escape
|
||||||
from django.utils.http import urlencode
|
from django.utils.http import urlencode
|
||||||
|
|
||||||
|
@ -183,8 +183,8 @@ class AdminViewBasicTestCase(TestCase):
|
||||||
"""
|
"""
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertLess(
|
self.assertLess(
|
||||||
response.content.index(force_bytes(text1)),
|
response.content.index(text1.encode()),
|
||||||
response.content.index(force_bytes(text2)),
|
response.content.index(text2.encode()),
|
||||||
(failing_msg or '') + '\nResponse:\n' + response.content.decode(response.charset)
|
(failing_msg or '') + '\nResponse:\n' + response.content.decode(response.charset)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -2161,16 +2161,14 @@ class AdminViewDeletedObjectsTest(TestCase):
|
||||||
cause them to be scheduled for deletion.
|
cause them to be scheduled for deletion.
|
||||||
"""
|
"""
|
||||||
pattern = re.compile(
|
pattern = re.compile(
|
||||||
force_bytes(
|
|
||||||
r'<li>Plot: <a href="%s">World Domination</a>\s*<ul>\s*'
|
r'<li>Plot: <a href="%s">World Domination</a>\s*<ul>\s*'
|
||||||
r'<li>Plot details: <a href="%s">almost finished</a>' % (
|
r'<li>Plot details: <a href="%s">almost finished</a>' % (
|
||||||
reverse('admin:admin_views_plot_change', args=(self.pl1.pk,)),
|
reverse('admin:admin_views_plot_change', args=(self.pl1.pk,)),
|
||||||
reverse('admin:admin_views_plotdetails_change', args=(self.pd1.pk,)),
|
reverse('admin:admin_views_plotdetails_change', args=(self.pd1.pk,)),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.v1.pk,)))
|
response = self.client.get(reverse('admin:admin_views_villain_delete', args=(self.v1.pk,)))
|
||||||
self.assertRegex(response.content, pattern)
|
self.assertRegex(response.content.decode(), pattern)
|
||||||
|
|
||||||
def test_cyclic(self):
|
def test_cyclic(self):
|
||||||
"""
|
"""
|
||||||
|
@ -5455,7 +5453,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
|
||||||
# Check the `change_view` link has the correct querystring.
|
# Check the `change_view` link has the correct querystring.
|
||||||
detail_link = re.search(
|
detail_link = re.search(
|
||||||
'<a href="(.*?)">{}</a>'.format(self.joepublicuser.username),
|
'<a href="(.*?)">{}</a>'.format(self.joepublicuser.username),
|
||||||
force_text(response.content)
|
response.content.decode()
|
||||||
)
|
)
|
||||||
self.assertURLEqual(detail_link.group(1), self.get_change_url())
|
self.assertURLEqual(detail_link.group(1), self.get_change_url())
|
||||||
|
|
||||||
|
@ -5467,21 +5465,21 @@ class AdminKeepChangeListFiltersTests(TestCase):
|
||||||
# Check the form action.
|
# Check the form action.
|
||||||
form_action = re.search(
|
form_action = re.search(
|
||||||
'<form action="(.*?)" method="post" id="user_form".*?>',
|
'<form action="(.*?)" method="post" id="user_form".*?>',
|
||||||
force_text(response.content)
|
response.content.decode()
|
||||||
)
|
)
|
||||||
self.assertURLEqual(form_action.group(1), '?%s' % self.get_preserved_filters_querystring())
|
self.assertURLEqual(form_action.group(1), '?%s' % self.get_preserved_filters_querystring())
|
||||||
|
|
||||||
# Check the history link.
|
# Check the history link.
|
||||||
history_link = re.search(
|
history_link = re.search(
|
||||||
'<a href="(.*?)" class="historylink">History</a>',
|
'<a href="(.*?)" class="historylink">History</a>',
|
||||||
force_text(response.content)
|
response.content.decode()
|
||||||
)
|
)
|
||||||
self.assertURLEqual(history_link.group(1), self.get_history_url())
|
self.assertURLEqual(history_link.group(1), self.get_history_url())
|
||||||
|
|
||||||
# Check the delete link.
|
# Check the delete link.
|
||||||
delete_link = re.search(
|
delete_link = re.search(
|
||||||
'<a href="(.*?)" class="deletelink">Delete</a>',
|
'<a href="(.*?)" class="deletelink">Delete</a>',
|
||||||
force_text(response.content)
|
response.content.decode()
|
||||||
)
|
)
|
||||||
self.assertURLEqual(delete_link.group(1), self.get_delete_url())
|
self.assertURLEqual(delete_link.group(1), self.get_delete_url())
|
||||||
|
|
||||||
|
@ -5531,7 +5529,7 @@ class AdminKeepChangeListFiltersTests(TestCase):
|
||||||
# Check the form action.
|
# Check the form action.
|
||||||
form_action = re.search(
|
form_action = re.search(
|
||||||
'<form action="(.*?)" method="post" id="user_form".*?>',
|
'<form action="(.*?)" method="post" id="user_form".*?>',
|
||||||
force_text(response.content)
|
response.content.decode()
|
||||||
)
|
)
|
||||||
self.assertURLEqual(form_action.group(1), '?%s' % self.get_preserved_filters_querystring())
|
self.assertURLEqual(form_action.group(1), '?%s' % self.get_preserved_filters_querystring())
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ from django.contrib.auth.hashers import (
|
||||||
)
|
)
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.test.utils import override_settings
|
from django.test.utils import override_settings
|
||||||
from django.utils.encoding import force_bytes
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import crypt
|
import crypt
|
||||||
|
@ -238,7 +237,7 @@ class TestUtilsHashPass(SimpleTestCase):
|
||||||
|
|
||||||
# Get the original salt (includes the original workload factor)
|
# Get the original salt (includes the original workload factor)
|
||||||
algorithm, data = encoded.split('$', 1)
|
algorithm, data = encoded.split('$', 1)
|
||||||
expected_call = (('wrong_password', force_bytes(data[:29])),)
|
expected_call = (('wrong_password', data[:29].encode()),)
|
||||||
self.assertEqual(hasher.encode.call_args_list, [expected_call] * 3)
|
self.assertEqual(hasher.encode.call_args_list, [expected_call] * 3)
|
||||||
|
|
||||||
def test_unusable(self):
|
def test_unusable(self):
|
||||||
|
|
|
@ -7,7 +7,6 @@ from django.contrib.auth.views import (
|
||||||
)
|
)
|
||||||
from django.test import RequestFactory, TestCase, override_settings
|
from django.test import RequestFactory, TestCase, override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.encoding import force_bytes
|
|
||||||
from django.utils.http import urlsafe_base64_encode
|
from django.utils.http import urlsafe_base64_encode
|
||||||
|
|
||||||
from .client import PasswordResetConfirmClient
|
from .client import PasswordResetConfirmClient
|
||||||
|
@ -48,7 +47,7 @@ class AuthTemplateTests(TestCase):
|
||||||
client = PasswordResetConfirmClient()
|
client = PasswordResetConfirmClient()
|
||||||
default_token_generator = PasswordResetTokenGenerator()
|
default_token_generator = PasswordResetTokenGenerator()
|
||||||
token = default_token_generator.make_token(self.user)
|
token = default_token_generator.make_token(self.user)
|
||||||
uidb64 = urlsafe_base64_encode(force_bytes(self.user.pk)).decode()
|
uidb64 = urlsafe_base64_encode(str(self.user.pk).encode()).decode()
|
||||||
url = reverse('password_reset_confirm', kwargs={'uidb64': uidb64, 'token': token})
|
url = reverse('password_reset_confirm', kwargs={'uidb64': uidb64, 'token': token})
|
||||||
response = client.get(url)
|
response = client.get(url)
|
||||||
self.assertContains(response, '<title>Enter new password</title>')
|
self.assertContains(response, '<title>Enter new password</title>')
|
||||||
|
|
|
@ -28,7 +28,6 @@ from django.middleware.csrf import CsrfViewMiddleware, get_token
|
||||||
from django.test import Client, TestCase, override_settings
|
from django.test import Client, TestCase, override_settings
|
||||||
from django.test.utils import patch_logger
|
from django.test.utils import patch_logger
|
||||||
from django.urls import NoReverseMatch, reverse, reverse_lazy
|
from django.urls import NoReverseMatch, reverse, reverse_lazy
|
||||||
from django.utils.encoding import force_text
|
|
||||||
from django.utils.translation import LANGUAGE_SESSION_KEY
|
from django.utils.translation import LANGUAGE_SESSION_KEY
|
||||||
|
|
||||||
from .client import PasswordResetConfirmClient
|
from .client import PasswordResetConfirmClient
|
||||||
|
@ -1150,7 +1149,7 @@ class ChangelistTests(AuthViewsTestCase):
|
||||||
# Test the link inside password field help_text.
|
# Test the link inside password field help_text.
|
||||||
rel_link = re.search(
|
rel_link = re.search(
|
||||||
r'you can change the password using <a href="([^"]*)">this form</a>',
|
r'you can change the password using <a href="([^"]*)">this form</a>',
|
||||||
force_text(response.content)
|
response.content.decode()
|
||||||
).groups()[0]
|
).groups()[0]
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
os.path.normpath(user_change_url + rel_link),
|
os.path.normpath(user_change_url + rel_link),
|
||||||
|
|
|
@ -12,7 +12,6 @@ from django.core.files import temp as tempfile
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.http.multipartparser import MultiPartParser, parse_header
|
from django.http.multipartparser import MultiPartParser, parse_header
|
||||||
from django.test import SimpleTestCase, TestCase, client, override_settings
|
from django.test import SimpleTestCase, TestCase, client, override_settings
|
||||||
from django.utils.encoding import force_bytes
|
|
||||||
|
|
||||||
from . import uploadhandler
|
from . import uploadhandler
|
||||||
from .models import FileModel
|
from .models import FileModel
|
||||||
|
@ -65,7 +64,7 @@ class FileUploadTests(TestCase):
|
||||||
post_data[key + '_hash'] = hashlib.sha1(post_data[key].read()).hexdigest()
|
post_data[key + '_hash'] = hashlib.sha1(post_data[key].read()).hexdigest()
|
||||||
post_data[key].seek(0)
|
post_data[key].seek(0)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
post_data[key + '_hash'] = hashlib.sha1(force_bytes(post_data[key])).hexdigest()
|
post_data[key + '_hash'] = hashlib.sha1(post_data[key].encode()).hexdigest()
|
||||||
|
|
||||||
response = self.client.post('/verify/', post_data)
|
response = self.client.post('/verify/', post_data)
|
||||||
|
|
||||||
|
@ -78,7 +77,7 @@ class FileUploadTests(TestCase):
|
||||||
'Content-Type: application/octet-stream',
|
'Content-Type: application/octet-stream',
|
||||||
'Content-Transfer-Encoding: base64',
|
'Content-Transfer-Encoding: base64',
|
||||||
'']))
|
'']))
|
||||||
payload.write(b"\r\n" + encode(force_bytes(content)) + b"\r\n")
|
payload.write(b'\r\n' + encode(content.encode()) + b'\r\n')
|
||||||
payload.write('--' + client.BOUNDARY + '--\r\n')
|
payload.write('--' + client.BOUNDARY + '--\r\n')
|
||||||
r = {
|
r = {
|
||||||
'CONTENT_LENGTH': len(payload),
|
'CONTENT_LENGTH': len(payload),
|
||||||
|
|
|
@ -3,7 +3,6 @@ import os
|
||||||
|
|
||||||
from django.core.files.uploadedfile import UploadedFile
|
from django.core.files.uploadedfile import UploadedFile
|
||||||
from django.http import HttpResponse, HttpResponseServerError, JsonResponse
|
from django.http import HttpResponse, HttpResponseServerError, JsonResponse
|
||||||
from django.utils.encoding import force_bytes, force_text
|
|
||||||
|
|
||||||
from .models import FileModel
|
from .models import FileModel
|
||||||
from .tests import UNICODE_FILENAME, UPLOAD_TO
|
from .tests import UNICODE_FILENAME, UPLOAD_TO
|
||||||
|
@ -42,7 +41,7 @@ def file_upload_view_verify(request):
|
||||||
if isinstance(value, UploadedFile):
|
if isinstance(value, UploadedFile):
|
||||||
new_hash = hashlib.sha1(value.read()).hexdigest()
|
new_hash = hashlib.sha1(value.read()).hexdigest()
|
||||||
else:
|
else:
|
||||||
new_hash = hashlib.sha1(force_bytes(value)).hexdigest()
|
new_hash = hashlib.sha1(value.encode()).hexdigest()
|
||||||
if new_hash != submitted_hash:
|
if new_hash != submitted_hash:
|
||||||
return HttpResponseServerError()
|
return HttpResponseServerError()
|
||||||
|
|
||||||
|
@ -151,7 +150,7 @@ def file_upload_content_type_extra(request):
|
||||||
"""
|
"""
|
||||||
params = {}
|
params = {}
|
||||||
for file_name, uploadedfile in request.FILES.items():
|
for file_name, uploadedfile in request.FILES.items():
|
||||||
params[file_name] = {k: force_text(v) for k, v in uploadedfile.content_type_extra.items()}
|
params[file_name] = {k: v.decode() for k, v in uploadedfile.content_type_extra.items()}
|
||||||
return JsonResponse(params)
|
return JsonResponse(params)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ from django.contrib.gis.shortcuts import numpy
|
||||||
from django.template import Context
|
from django.template import Context
|
||||||
from django.template.engine import Engine
|
from django.template.engine import Engine
|
||||||
from django.test import SimpleTestCase
|
from django.test import SimpleTestCase
|
||||||
from django.utils.encoding import force_bytes
|
|
||||||
|
|
||||||
from ..test_data import TestDataMixin
|
from ..test_data import TestDataMixin
|
||||||
|
|
||||||
|
@ -160,7 +159,7 @@ class GEOSTest(SimpleTestCase, TestDataMixin):
|
||||||
ref_pnt = GEOSGeometry('POINT(5 23)')
|
ref_pnt = GEOSGeometry('POINT(5 23)')
|
||||||
|
|
||||||
wkt_f = BytesIO()
|
wkt_f = BytesIO()
|
||||||
wkt_f.write(force_bytes(ref_pnt.wkt))
|
wkt_f.write(ref_pnt.wkt.encode())
|
||||||
wkb_f = BytesIO()
|
wkb_f = BytesIO()
|
||||||
wkb_f.write(bytes(ref_pnt.wkb))
|
wkb_f.write(bytes(ref_pnt.wkb))
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ from django.core.mail.backends import console, dummy, filebased, locmem, smtp
|
||||||
from django.core.mail.message import BadHeaderError, sanitize_address
|
from django.core.mail.message import BadHeaderError, sanitize_address
|
||||||
from django.test import SimpleTestCase, override_settings
|
from django.test import SimpleTestCase, override_settings
|
||||||
from django.test.utils import requires_tz_support
|
from django.test.utils import requires_tz_support
|
||||||
from django.utils.encoding import force_bytes, force_text
|
|
||||||
from django.utils.translation import gettext_lazy
|
from django.utils.translation import gettext_lazy
|
||||||
|
|
||||||
|
|
||||||
|
@ -800,7 +799,7 @@ class BaseEmailBackendTests(HeadersCheckMixin):
|
||||||
self.assertEqual(num_sent, 1)
|
self.assertEqual(num_sent, 1)
|
||||||
message = self.get_the_message()
|
message = self.get_the_message()
|
||||||
self.assertEqual(message["subject"], '=?utf-8?q?Ch=C3=A8re_maman?=')
|
self.assertEqual(message["subject"], '=?utf-8?q?Ch=C3=A8re_maman?=')
|
||||||
self.assertEqual(force_text(message.get_payload(decode=True)), 'Je t\'aime très fort')
|
self.assertEqual(message.get_payload(decode=True).decode(), 'Je t\'aime très fort')
|
||||||
|
|
||||||
def test_send_long_lines(self):
|
def test_send_long_lines(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1083,7 +1082,7 @@ class FileBackendTests(BaseEmailBackendTests, SimpleTestCase):
|
||||||
messages = []
|
messages = []
|
||||||
for filename in os.listdir(self.tmp_dir):
|
for filename in os.listdir(self.tmp_dir):
|
||||||
with open(os.path.join(self.tmp_dir, filename), 'rb') as fp:
|
with open(os.path.join(self.tmp_dir, filename), 'rb') as fp:
|
||||||
session = fp.read().split(force_bytes('\n' + ('-' * 79) + '\n', encoding='ascii'))
|
session = fp.read().split(b'\n' + (b'-' * 79) + b'\n')
|
||||||
messages.extend(message_from_bytes(m) for m in session if m)
|
messages.extend(message_from_bytes(m) for m in session if m)
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
|
@ -1140,7 +1139,7 @@ class ConsoleBackendTests(BaseEmailBackendTests, SimpleTestCase):
|
||||||
|
|
||||||
def get_mailbox_content(self):
|
def get_mailbox_content(self):
|
||||||
messages = self.stream.getvalue().split('\n' + ('-' * 79) + '\n')
|
messages = self.stream.getvalue().split('\n' + ('-' * 79) + '\n')
|
||||||
return [message_from_bytes(force_bytes(m)) for m in messages if m]
|
return [message_from_bytes(str(m).encode()) for m in messages if m]
|
||||||
|
|
||||||
def test_console_stream_kwarg(self):
|
def test_console_stream_kwarg(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1149,7 +1148,7 @@ class ConsoleBackendTests(BaseEmailBackendTests, SimpleTestCase):
|
||||||
s = StringIO()
|
s = StringIO()
|
||||||
connection = mail.get_connection('django.core.mail.backends.console.EmailBackend', stream=s)
|
connection = mail.get_connection('django.core.mail.backends.console.EmailBackend', stream=s)
|
||||||
send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
|
send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
|
||||||
message = force_bytes(s.getvalue().split('\n' + ('-' * 79) + '\n')[0])
|
message = str(s.getvalue().split('\n' + ('-' * 79) + '\n')[0]).encode()
|
||||||
self.assertMessageHasHeaders(message, {
|
self.assertMessageHasHeaders(message, {
|
||||||
('MIME-Version', '1.0'),
|
('MIME-Version', '1.0'),
|
||||||
('Content-Type', 'text/plain; charset="utf-8"'),
|
('Content-Type', 'text/plain; charset="utf-8"'),
|
||||||
|
|
|
@ -16,7 +16,6 @@ from django.template import TemplateDoesNotExist
|
||||||
from django.test import RequestFactory, SimpleTestCase, override_settings
|
from django.test import RequestFactory, SimpleTestCase, override_settings
|
||||||
from django.test.utils import LoggingCaptureMixin, patch_logger
|
from django.test.utils import LoggingCaptureMixin, patch_logger
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.encoding import force_bytes
|
|
||||||
from django.utils.functional import SimpleLazyObject
|
from django.utils.functional import SimpleLazyObject
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
from django.utils.version import PY36
|
from django.utils.version import PY36
|
||||||
|
@ -325,7 +324,7 @@ class ExceptionReporterTests(SimpleTestCase):
|
||||||
|
|
||||||
for newline in ['\n', '\r\n', '\r']:
|
for newline in ['\n', '\r\n', '\r']:
|
||||||
fd, filename = tempfile.mkstemp(text=False)
|
fd, filename = tempfile.mkstemp(text=False)
|
||||||
os.write(fd, force_bytes(newline.join(LINES) + newline))
|
os.write(fd, (newline.join(LINES) + newline).encode())
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue