diff --git a/tests/admin_filters/tests.py b/tests/admin_filters/tests.py
index 0df02708a8..4dc6c3365a 100644
--- a/tests/admin_filters/tests.py
+++ b/tests/admin_filters/tests.py
@@ -11,7 +11,6 @@ from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.core.exceptions import ImproperlyConfigured
from django.test import RequestFactory, TestCase, override_settings
-from django.utils.encoding import force_text
from .models import Book, Bookmark, Department, Employee, TaggedItem
@@ -332,7 +331,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][4]
- self.assertEqual(force_text(filterspec.title), 'date registered')
+ self.assertEqual(filterspec.title, 'date registered')
choice = select_by(filterspec.choices(changelist), "display", "Today")
self.assertIs(choice['selected'], True)
self.assertEqual(
@@ -357,7 +356,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][4]
- self.assertEqual(force_text(filterspec.title), 'date registered')
+ self.assertEqual(filterspec.title, 'date registered')
choice = select_by(filterspec.choices(changelist), "display", "This month")
self.assertIs(choice['selected'], True)
self.assertEqual(
@@ -382,7 +381,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][4]
- self.assertEqual(force_text(filterspec.title), 'date registered')
+ self.assertEqual(filterspec.title, 'date registered')
choice = select_by(filterspec.choices(changelist), "display", "This year")
self.assertIs(choice['selected'], True)
self.assertEqual(
@@ -405,7 +404,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][4]
- self.assertEqual(force_text(filterspec.title), 'date registered')
+ self.assertEqual(filterspec.title, 'date registered')
choice = select_by(filterspec.choices(changelist), "display", "Past 7 days")
self.assertIs(choice['selected'], True)
self.assertEqual(
@@ -427,7 +426,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][4]
- self.assertEqual(force_text(filterspec.title), 'date registered')
+ self.assertEqual(filterspec.title, 'date registered')
choice = select_by(filterspec.choices(changelist), 'display', 'No date')
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?date_registered__isnull=True')
@@ -442,7 +441,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][4]
- self.assertEqual(force_text(filterspec.title), 'date registered')
+ self.assertEqual(filterspec.title, 'date registered')
choice = select_by(filterspec.choices(changelist), 'display', 'Has date')
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?date_registered__isnull=False')
@@ -469,7 +468,7 @@ class ListFiltersTests(TestCase):
# Make sure the last choice is None and is selected
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'year')
+ self.assertEqual(filterspec.title, 'year')
choices = list(filterspec.choices(changelist))
self.assertIs(choices[-1]['selected'], True)
self.assertEqual(choices[-1]['query_string'], '?year__isnull=True')
@@ -479,7 +478,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'year')
+ self.assertEqual(filterspec.title, 'year')
choices = list(filterspec.choices(changelist))
self.assertIs(choices[2]['selected'], True)
self.assertEqual(choices[2]['query_string'], '?year=2002')
@@ -520,7 +519,7 @@ class ListFiltersTests(TestCase):
# Make sure the last choice is None and is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'Verbose Author')
+ self.assertEqual(filterspec.title, 'Verbose Author')
choices = list(filterspec.choices(changelist))
self.assertIs(choices[-1]['selected'], True)
self.assertEqual(choices[-1]['query_string'], '?author__isnull=True')
@@ -530,7 +529,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'Verbose Author')
+ self.assertEqual(filterspec.title, 'Verbose Author')
# order of choices depends on User model, which has no order
choice = select_by(filterspec.choices(changelist), "display", "alfred")
self.assertIs(choice['selected'], True)
@@ -556,7 +555,7 @@ class ListFiltersTests(TestCase):
# Make sure the last choice is None and is selected
filterspec = changelist.get_filters(request)[0][2]
- self.assertEqual(force_text(filterspec.title), 'Verbose Contributors')
+ self.assertEqual(filterspec.title, 'Verbose Contributors')
choices = list(filterspec.choices(changelist))
self.assertIs(choices[-1]['selected'], True)
self.assertEqual(choices[-1]['query_string'], '?contributors__isnull=True')
@@ -566,7 +565,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][2]
- self.assertEqual(force_text(filterspec.title), 'Verbose Contributors')
+ self.assertEqual(filterspec.title, 'Verbose Contributors')
choice = select_by(filterspec.choices(changelist), "display", "bob")
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?contributors__id__exact=%d' % self.bob.pk)
@@ -584,7 +583,7 @@ class ListFiltersTests(TestCase):
# Make sure the last choice is None and is selected
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'book')
+ self.assertEqual(filterspec.title, 'book')
choices = list(filterspec.choices(changelist))
self.assertIs(choices[-1]['selected'], True)
self.assertEqual(choices[-1]['query_string'], '?books_authored__isnull=True')
@@ -594,7 +593,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'book')
+ self.assertEqual(filterspec.title, 'book')
choice = select_by(filterspec.choices(changelist), "display", self.bio_book.title)
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?books_authored__id__exact=%d' % self.bio_book.pk)
@@ -609,7 +608,7 @@ class ListFiltersTests(TestCase):
# Make sure the last choice is None and is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'book')
+ self.assertEqual(filterspec.title, 'book')
choices = list(filterspec.choices(changelist))
self.assertIs(choices[-1]['selected'], True)
self.assertEqual(choices[-1]['query_string'], '?books_contributed__isnull=True')
@@ -619,7 +618,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'book')
+ self.assertEqual(filterspec.title, 'book')
choice = select_by(filterspec.choices(changelist), "display", self.django_book.title)
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?books_contributed__id__exact=%d' % self.django_book.pk)
@@ -715,7 +714,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][3]
- self.assertEqual(force_text(filterspec.title), 'is best seller')
+ self.assertEqual(filterspec.title, 'is best seller')
choice = select_by(filterspec.choices(changelist), "display", "No")
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?is_best_seller__exact=0')
@@ -729,7 +728,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][3]
- self.assertEqual(force_text(filterspec.title), 'is best seller')
+ self.assertEqual(filterspec.title, 'is best seller')
choice = select_by(filterspec.choices(changelist), "display", "Yes")
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?is_best_seller__exact=1')
@@ -743,7 +742,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][3]
- self.assertEqual(force_text(filterspec.title), 'is best seller')
+ self.assertEqual(filterspec.title, 'is best seller')
choice = select_by(filterspec.choices(changelist), "display", "Unknown")
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?is_best_seller__isnull=True')
@@ -777,7 +776,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[0]['display'], 'All')
self.assertIs(choices[0]['selected'], True)
@@ -793,7 +792,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[1]['display'], 'the 1980\'s')
self.assertIs(choices[1]['selected'], True)
@@ -809,7 +808,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[2]['display'], 'the 1990\'s')
self.assertIs(choices[2]['selected'], True)
@@ -825,7 +824,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[3]['display'], 'the 2000\'s')
self.assertIs(choices[3]['selected'], True)
@@ -841,7 +840,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choices are selected
filterspec = changelist.get_filters(request)[0][1]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[3]['display'], 'the 2000\'s')
self.assertIs(choices[3]['selected'], True)
@@ -851,7 +850,7 @@ class ListFiltersTests(TestCase):
)
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'Verbose Author')
+ self.assertEqual(filterspec.title, 'Verbose Author')
choice = select_by(filterspec.choices(changelist), "display", "alfred")
self.assertIs(choice['selected'], True)
self.assertEqual(choice['query_string'], '?author__id__exact=%s&publication-decade=the+00s' % self.alfred.pk)
@@ -903,7 +902,7 @@ class ListFiltersTests(TestCase):
changelist = self.get_changelist(request, Book, modeladmin)
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = list(filterspec.choices(changelist))
self.assertEqual(len(choices), 3)
@@ -932,7 +931,7 @@ class ListFiltersTests(TestCase):
self.assertEqual(list(queryset), [self.bio_book])
filterspec = changelist.get_filters(request)[0][-1]
- self.assertEqual(force_text(filterspec.title), 'number')
+ self.assertEqual(filterspec.title, 'number')
choices = list(filterspec.choices(changelist))
self.assertIs(choices[2]['selected'], True)
self.assertEqual(choices[2]['query_string'], '?no=207')
@@ -953,7 +952,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[2]['display'], 'the 1990\'s')
self.assertIs(choices[2]['selected'], True)
@@ -970,7 +969,7 @@ class ListFiltersTests(TestCase):
# Make sure the correct choice is selected
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[2]['display'], 'the 1990\'s')
self.assertIs(choices[2]['selected'], True)
@@ -990,7 +989,7 @@ class ListFiltersTests(TestCase):
self.assertEqual(list(queryset), [self.john])
filterspec = changelist.get_filters(request)[0][-1]
- self.assertEqual(force_text(filterspec.title), 'department')
+ self.assertEqual(filterspec.title, 'department')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[1]['display'], 'DEV')
self.assertIs(choices[1]['selected'], True)
@@ -1010,7 +1009,7 @@ class ListFiltersTests(TestCase):
self.assertEqual(list(queryset), [self.john])
filterspec = changelist.get_filters(request)[0][-1]
- self.assertEqual(force_text(filterspec.title), 'department')
+ self.assertEqual(filterspec.title, 'department')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[1]['display'], 'DEV')
self.assertIs(choices[1]['selected'], True)
@@ -1030,7 +1029,7 @@ class ListFiltersTests(TestCase):
self.assertEqual(list(queryset), [self.jack, self.john])
filterspec = changelist.get_filters(request)[0][-1]
- self.assertEqual(force_text(filterspec.title), 'department')
+ self.assertEqual(filterspec.title, 'department')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[0]['display'], 'All')
@@ -1055,7 +1054,7 @@ class ListFiltersTests(TestCase):
self.assertEqual(list(queryset), [self.john])
filterspec = changelist.get_filters(request)[0][-1]
- self.assertEqual(force_text(filterspec.title), 'department')
+ self.assertEqual(filterspec.title, 'department')
choices = list(filterspec.choices(changelist))
self.assertEqual(choices[0]['display'], 'All')
@@ -1079,7 +1078,7 @@ class ListFiltersTests(TestCase):
def _test_choices(request, expected_displays):
changelist = self.get_changelist(request, Book, modeladmin)
filterspec = changelist.get_filters(request)[0][0]
- self.assertEqual(force_text(filterspec.title), 'publication decade')
+ self.assertEqual(filterspec.title, 'publication decade')
choices = tuple(c['display'] for c in filterspec.choices(changelist))
self.assertEqual(choices, expected_displays)
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py
index c8f5d2a20d..88a0260358 100644
--- a/tests/admin_scripts/tests.py
+++ b/tests/admin_scripts/tests.py
@@ -27,7 +27,6 @@ from django.db.migrations.recorder import MigrationRecorder
from django.test import (
LiveServerTestCase, SimpleTestCase, TestCase, override_settings,
)
-from django.utils.encoding import force_text
custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates')
@@ -196,7 +195,6 @@ class AdminScriptTestCase(unittest.TestCase):
def assertOutput(self, stream, msg, regex=False):
"Utility assertion: assert that the given message exists in the output"
- stream = force_text(stream)
if regex:
self.assertIsNotNone(
re.search(msg, stream),
@@ -207,7 +205,6 @@ class AdminScriptTestCase(unittest.TestCase):
def assertNotInOutput(self, stream, msg):
"Utility assertion: assert that the given message doesn't exist in the output"
- stream = force_text(stream)
self.assertNotIn(msg, stream, "'%s' matches actual output text '%s'" % (msg, stream))
##########################################################################
@@ -2021,7 +2018,7 @@ class StartProject(LiveServerTestCase, AdminScriptTestCase):
self.assertNoOutput(err)
test_manage_py = os.path.join(testproject_dir, 'manage.py')
with open(test_manage_py, 'r') as fp:
- content = force_text(fp.read())
+ content = fp.read()
self.assertIn("project_name = 'another_project'", content)
self.assertIn("project_directory = '%s'" % testproject_dir, content)
diff --git a/tests/auth_tests/test_deprecated_views.py b/tests/auth_tests/test_deprecated_views.py
index d5088b9d8a..285638027e 100644
--- a/tests/auth_tests/test_deprecated_views.py
+++ b/tests/auth_tests/test_deprecated_views.py
@@ -14,7 +14,6 @@ from django.http import QueryDict
from django.test import TestCase, override_settings
from django.test.utils import ignore_warnings, patch_logger
from django.utils.deprecation import RemovedInDjango21Warning
-from django.utils.encoding import force_text
from .models import CustomUser, UUIDUser
from .settings import AUTH_TEMPLATES
@@ -52,7 +51,7 @@ class AuthViewsTestCase(TestCase):
def assertFormError(self, response, error):
"""Assert that error is found in response.context['form'] errors"""
form_errors = list(itertools.chain(*response.context['form'].errors.values()))
- self.assertIn(force_text(error), form_errors)
+ self.assertIn(str(error), form_errors)
def assertURLEqual(self, url, expected, parse_qs=False):
"""
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py
index bbcd75124a..abd5b0f8df 100644
--- a/tests/auth_tests/test_forms.py
+++ b/tests/auth_tests/test_forms.py
@@ -16,7 +16,6 @@ from django.core.mail import EmailMultiAlternatives
from django.forms.fields import CharField, Field, IntegerField
from django.test import SimpleTestCase, TestCase, override_settings
from django.utils import translation
-from django.utils.encoding import force_text
from django.utils.text import capfirst
from django.utils.translation import ugettext as _
@@ -51,7 +50,7 @@ class UserCreationFormTest(TestDataMixin, TestCase):
form = UserCreationForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form["username"].errors,
- [force_text(User._meta.get_field('username').error_messages['unique'])])
+ [str(User._meta.get_field('username').error_messages['unique'])])
def test_invalid_data(self):
data = {
@@ -62,7 +61,7 @@ class UserCreationFormTest(TestDataMixin, TestCase):
form = UserCreationForm(data)
self.assertFalse(form.is_valid())
validator = next(v for v in User._meta.get_field('username').validators if v.code == 'invalid')
- self.assertEqual(form["username"].errors, [force_text(validator.message)])
+ self.assertEqual(form["username"].errors, [str(validator.message)])
def test_password_verification(self):
# The verification password is incorrect.
@@ -74,13 +73,13 @@ class UserCreationFormTest(TestDataMixin, TestCase):
form = UserCreationForm(data)
self.assertFalse(form.is_valid())
self.assertEqual(form["password2"].errors,
- [force_text(form.error_messages['password_mismatch'])])
+ [str(form.error_messages['password_mismatch'])])
def test_both_passwords(self):
# One (or both) passwords weren't given
data = {'username': 'jsmith'}
form = UserCreationForm(data)
- required_error = [force_text(Field.default_error_messages['required'])]
+ required_error = [str(Field.default_error_messages['required'])]
self.assertFalse(form.is_valid())
self.assertEqual(form['password1'].errors, required_error)
self.assertEqual(form['password2'].errors, required_error)
@@ -257,9 +256,9 @@ class AuthenticationFormTest(TestDataMixin, TestCase):
self.assertFalse(form.is_valid())
self.assertEqual(
form.non_field_errors(), [
- force_text(form.error_messages['invalid_login'] % {
+ form.error_messages['invalid_login'] % {
'username': User._meta.get_field('username').verbose_name
- })
+ }
]
)
@@ -271,7 +270,7 @@ class AuthenticationFormTest(TestDataMixin, TestCase):
}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
- self.assertEqual(form.non_field_errors(), [force_text(form.error_messages['inactive'])])
+ self.assertEqual(form.non_field_errors(), [str(form.error_messages['inactive'])])
def test_login_failed(self):
signal_calls = []
@@ -300,7 +299,7 @@ class AuthenticationFormTest(TestDataMixin, TestCase):
}
form = AuthenticationForm(None, data)
self.assertFalse(form.is_valid())
- self.assertEqual(form.non_field_errors(), [force_text(form.error_messages['inactive'])])
+ self.assertEqual(form.non_field_errors(), [str(form.error_messages['inactive'])])
def test_custom_login_allowed_policy(self):
# The user is inactive, but our custom form policy allows them to log in.
@@ -421,7 +420,7 @@ class SetPasswordFormTest(TestDataMixin, TestCase):
self.assertFalse(form.is_valid())
self.assertEqual(
form["new_password2"].errors,
- [force_text(form.error_messages['password_mismatch'])]
+ [str(form.error_messages['password_mismatch'])]
)
@mock.patch('django.contrib.auth.password_validation.password_changed')
@@ -499,7 +498,7 @@ class PasswordChangeFormTest(TestDataMixin, TestCase):
}
form = PasswordChangeForm(user, data)
self.assertFalse(form.is_valid())
- self.assertEqual(form["old_password"].errors, [force_text(form.error_messages['password_incorrect'])])
+ self.assertEqual(form["old_password"].errors, [str(form.error_messages['password_incorrect'])])
def test_password_verification(self):
# The two new passwords do not match.
@@ -511,7 +510,7 @@ class PasswordChangeFormTest(TestDataMixin, TestCase):
}
form = PasswordChangeForm(user, data)
self.assertFalse(form.is_valid())
- self.assertEqual(form["new_password2"].errors, [force_text(form.error_messages['password_mismatch'])])
+ self.assertEqual(form["new_password2"].errors, [str(form.error_messages['password_mismatch'])])
@mock.patch('django.contrib.auth.password_validation.password_changed')
def test_success(self, password_changed):
@@ -557,7 +556,7 @@ class UserChangeFormTest(TestDataMixin, TestCase):
form = UserChangeForm(data, instance=user)
self.assertFalse(form.is_valid())
validator = next(v for v in User._meta.get_field('username').validators if v.code == 'invalid')
- self.assertEqual(form["username"].errors, [force_text(validator.message)])
+ self.assertEqual(form["username"].errors, [str(validator.message)])
def test_bug_14242(self):
# A regression test, introduce by adding an optimization for the
diff --git a/tests/auth_tests/test_templates.py b/tests/auth_tests/test_templates.py
index a1d14c9774..b2c1d654a6 100644
--- a/tests/auth_tests/test_templates.py
+++ b/tests/auth_tests/test_templates.py
@@ -7,7 +7,7 @@ from django.contrib.auth.views import (
)
from django.test import RequestFactory, TestCase, override_settings
from django.urls import reverse
-from django.utils.encoding import force_bytes, force_text
+from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
from .client import PasswordResetConfirmClient
@@ -48,7 +48,7 @@ class AuthTemplateTests(TestCase):
client = PasswordResetConfirmClient()
default_token_generator = PasswordResetTokenGenerator()
token = default_token_generator.make_token(self.user)
- uidb64 = force_text(urlsafe_base64_encode(force_bytes(self.user.pk)))
+ uidb64 = urlsafe_base64_encode(force_bytes(self.user.pk)).decode()
url = reverse('password_reset_confirm', kwargs={'uidb64': uidb64, 'token': token})
response = client.get(url)
self.assertContains(response, '
Enter new password')
diff --git a/tests/auth_tests/test_views.py b/tests/auth_tests/test_views.py
index dd87a5bf00..1e18e0c73b 100644
--- a/tests/auth_tests/test_views.py
+++ b/tests/auth_tests/test_views.py
@@ -68,7 +68,7 @@ class AuthViewsTestCase(TestCase):
def assertFormError(self, response, error):
"""Assert that error is found in response.context['form'] errors"""
form_errors = list(itertools.chain(*response.context['form'].errors.values()))
- self.assertIn(force_text(error), form_errors)
+ self.assertIn(str(error), form_errors)
def assertURLEqual(self, url, expected, parse_qs=False):
"""
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index ef77b28458..79a5120f71 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -41,7 +41,6 @@ from django.utils.cache import (
patch_response_headers, patch_vary_headers,
)
from django.utils.deprecation import RemovedInDjango21Warning
-from django.utils.encoding import force_text
from django.views.decorators.cache import cache_page
from .models import Poll, expensive_calculation
@@ -1789,7 +1788,7 @@ class CacheI18nTest(TestCase):
request = self.factory.get(self.path)
# This is tightly coupled to the implementation,
# but it's the most straightforward way to test the key.
- tz = force_text(timezone.get_current_timezone_name(), errors='ignore')
+ tz = timezone.get_current_timezone_name()
tz = tz.encode('ascii', 'ignore').decode('ascii').replace(' ', '_')
response = HttpResponse()
key = learn_cache_key(request, response)
@@ -1801,7 +1800,7 @@ class CacheI18nTest(TestCase):
def test_cache_key_no_i18n(self):
request = self.factory.get(self.path)
lang = translation.get_language()
- tz = force_text(timezone.get_current_timezone_name(), errors='ignore')
+ tz = timezone.get_current_timezone_name()
tz = tz.encode('ascii', 'ignore').decode('ascii').replace(' ', '_')
response = HttpResponse()
key = learn_cache_key(request, response)
diff --git a/tests/check_framework/tests.py b/tests/check_framework/tests.py
index 46e4095a38..2128da3dc6 100644
--- a/tests/check_framework/tests.py
+++ b/tests/check_framework/tests.py
@@ -12,7 +12,6 @@ from django.test import SimpleTestCase
from django.test.utils import (
isolate_apps, override_settings, override_system_checks,
)
-from django.utils.encoding import force_text
from .models import SimpleModel, my_check
@@ -73,39 +72,39 @@ class MessageTests(SimpleTestCase):
def test_printing(self):
e = Error("Message", hint="Hint", obj=DummyObj())
expected = "obj: Message\n\tHINT: Hint"
- self.assertEqual(force_text(e), expected)
+ self.assertEqual(str(e), expected)
def test_printing_no_hint(self):
e = Error("Message", obj=DummyObj())
expected = "obj: Message"
- self.assertEqual(force_text(e), expected)
+ self.assertEqual(str(e), expected)
def test_printing_no_object(self):
e = Error("Message", hint="Hint")
expected = "?: Message\n\tHINT: Hint"
- self.assertEqual(force_text(e), expected)
+ self.assertEqual(str(e), expected)
def test_printing_with_given_id(self):
e = Error("Message", hint="Hint", obj=DummyObj(), id="ID")
expected = "obj: (ID) Message\n\tHINT: Hint"
- self.assertEqual(force_text(e), expected)
+ self.assertEqual(str(e), expected)
def test_printing_field_error(self):
field = SimpleModel._meta.get_field('field')
e = Error("Error", obj=field)
expected = "check_framework.SimpleModel.field: Error"
- self.assertEqual(force_text(e), expected)
+ self.assertEqual(str(e), expected)
def test_printing_model_error(self):
e = Error("Error", obj=SimpleModel)
expected = "check_framework.SimpleModel: Error"
- self.assertEqual(force_text(e), expected)
+ self.assertEqual(str(e), expected)
def test_printing_manager_error(self):
manager = SimpleModel.manager
e = Error("Error", obj=manager)
expected = "check_framework.SimpleModel.manager: Error"
- self.assertEqual(force_text(e), expected)
+ self.assertEqual(str(e), expected)
def test_equal_to_self(self):
e = Error("Error", obj=SimpleModel)
diff --git a/tests/contenttypes_tests/tests.py b/tests/contenttypes_tests/tests.py
index eecdaa91da..794b1e34ef 100644
--- a/tests/contenttypes_tests/tests.py
+++ b/tests/contenttypes_tests/tests.py
@@ -16,7 +16,6 @@ from django.test import (
SimpleTestCase, TestCase, TransactionTestCase, override_settings,
)
from django.test.utils import captured_stdout, isolate_apps
-from django.utils.encoding import force_text
from .models import (
Article, Author, ModelWithNullFKToSite, Post, SchemeIncludedURL,
@@ -134,7 +133,7 @@ class ContentTypesViewsTests(TestCase):
ct = ContentType.objects.get_for_model(ModelCreatedOnTheFly)
self.assertEqual(ct.app_label, 'my_great_app')
self.assertEqual(ct.model, 'modelcreatedonthefly')
- self.assertEqual(force_text(ct), 'modelcreatedonthefly')
+ self.assertEqual(str(ct), 'modelcreatedonthefly')
@override_settings(SILENCED_SYSTEM_CHECKS=['fields.W342']) # ForeignKey(unique=True)
@@ -144,9 +143,7 @@ class GenericForeignKeyTests(SimpleTestCase):
def test_str(self):
class Model(models.Model):
field = GenericForeignKey()
- expected = "contenttypes_tests.Model.field"
- actual = force_text(Model.field)
- self.assertEqual(expected, actual)
+ self.assertEqual(str(Model.field), "contenttypes_tests.Model.field")
def test_missing_content_type_field(self):
class TaggedItem(models.Model):
diff --git a/tests/csrf_tests/test_context_processor.py b/tests/csrf_tests/test_context_processor.py
index 5db0116db0..62e4365cd8 100644
--- a/tests/csrf_tests/test_context_processor.py
+++ b/tests/csrf_tests/test_context_processor.py
@@ -2,14 +2,13 @@ from django.http import HttpRequest
from django.middleware.csrf import _compare_salted_tokens as equivalent_tokens
from django.template.context_processors import csrf
from django.test import SimpleTestCase
-from django.utils.encoding import force_text
class TestContextProcessor(SimpleTestCase):
- def test_force_text_on_token(self):
+ def test_force_token_to_string(self):
request = HttpRequest()
test_token = '1bcdefghij2bcdefghij3bcdefghij4bcdefghij5bcdefghij6bcdefghijABCD'
request.META['CSRF_COOKIE'] = test_token
token = csrf(request).get('csrf_token')
- self.assertTrue(equivalent_tokens(force_text(token), test_token))
+ self.assertTrue(equivalent_tokens(str(token), test_token))
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index 89edea424e..a25eae18a6 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -15,7 +15,6 @@ from django.core.management.commands.dumpdata import ProxyModelWarning
from django.core.serializers.base import ProgressBar
from django.db import IntegrityError, connection
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
-from django.utils.encoding import force_text
from .models import (
Article, Category, PrimaryKeyUUIDModel, ProxySpy, Spy, Tag, Visa,
@@ -584,7 +583,7 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_loaddata_verbosity_three(self):
output = StringIO()
management.call_command('loaddata', 'fixture1.json', verbosity=3, stdout=output, stderr=output)
- command_output = force_text(output.getvalue())
+ command_output = output.getvalue()
self.assertIn(
"\rProcessed 1 object(s).\rProcessed 2 object(s)."
"\rProcessed 3 object(s).\rProcessed 4 object(s).\n",
diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py
index c13fbdf5c8..2a1ec44f66 100644
--- a/tests/forms_tests/tests/test_forms.py
+++ b/tests/forms_tests/tests/test_forms.py
@@ -20,7 +20,6 @@ from django.http import QueryDict
from django.template import Context, Template
from django.test import SimpleTestCase
from django.utils.datastructures import MultiValueDict
-from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
@@ -3361,7 +3360,7 @@ Good luck picking a username that doesn't already exist.
if not self:
return ''
return '%s
' % ''.join(
- '%s
' % force_text(e) for e in self)
+ '%s
' % e for e in self)
class CommentForm(Form):
name = CharField(max_length=50, required=False)
@@ -3471,9 +3470,9 @@ Good luck picking a username that doesn't already exist.
form = SimpleForm()
self.assertTrue(hasattr(SimpleForm, '__html__'))
- self.assertEqual(force_text(form), form.__html__())
+ self.assertEqual(str(form), form.__html__())
self.assertTrue(hasattr(form['username'], '__html__'))
- self.assertEqual(force_text(form['username']), form['username'].__html__())
+ self.assertEqual(str(form['username']), form['username'].__html__())
def test_use_required_attribute_true(self):
class MyForm(Form):
diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py
index ed8331ad72..3c3228fafc 100644
--- a/tests/forms_tests/tests/test_formsets.py
+++ b/tests/forms_tests/tests/test_formsets.py
@@ -9,7 +9,6 @@ from django.forms import (
from django.forms.formsets import BaseFormSet, formset_factory
from django.forms.utils import ErrorList
from django.test import SimpleTestCase
-from django.utils.encoding import force_text
class Choice(Form):
@@ -1251,7 +1250,7 @@ class FormsFormsetTestCase(SimpleTestCase):
def test_html_safe(self):
formset = self.make_choiceformset()
self.assertTrue(hasattr(formset, '__html__'))
- self.assertEqual(force_text(formset), formset.__html__())
+ self.assertEqual(str(formset), formset.__html__())
data = {
diff --git a/tests/forms_tests/tests/test_media.py b/tests/forms_tests/tests/test_media.py
index cd5cc1f804..72db13ef21 100644
--- a/tests/forms_tests/tests/test_media.py
+++ b/tests/forms_tests/tests/test_media.py
@@ -1,7 +1,6 @@
from django.forms import CharField, Form, Media, MultiWidget, TextInput
from django.template import Context, Template
from django.test import SimpleTestCase, override_settings
-from django.utils.encoding import force_text
@override_settings(
@@ -518,4 +517,4 @@ class FormsMediaTestCase(SimpleTestCase):
def test_html_safe(self):
media = Media(css={'all': ['/path/to/css']}, js=['/path/to/js'])
self.assertTrue(hasattr(Media, '__html__'))
- self.assertEqual(force_text(media), media.__html__())
+ self.assertEqual(str(media), media.__html__())
diff --git a/tests/forms_tests/tests/test_utils.py b/tests/forms_tests/tests/test_utils.py
index f52c195637..68991319e2 100644
--- a/tests/forms_tests/tests/test_utils.py
+++ b/tests/forms_tests/tests/test_utils.py
@@ -3,7 +3,6 @@ import copy
from django.core.exceptions import ValidationError
from django.forms.utils import ErrorDict, ErrorList, flatatt
from django.test import SimpleTestCase
-from django.utils.encoding import force_text
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy
@@ -158,9 +157,9 @@ class FormsUtilsTestCase(SimpleTestCase):
e = ErrorDict()
e['username'] = 'Invalid username.'
self.assertTrue(hasattr(ErrorDict, '__html__'))
- self.assertEqual(force_text(e), e.__html__())
+ self.assertEqual(str(e), e.__html__())
def test_error_list_html_safe(self):
e = ErrorList(['Invalid username.'])
self.assertTrue(hasattr(ErrorList, '__html__'))
- self.assertEqual(force_text(e), e.__html__())
+ self.assertEqual(str(e), e.__html__())
diff --git a/tests/i18n/test_compilation.py b/tests/i18n/test_compilation.py
index ca7dfd4309..7d3215d4a8 100644
--- a/tests/i18n/test_compilation.py
+++ b/tests/i18n/test_compilation.py
@@ -15,7 +15,6 @@ from django.core.management.utils import find_command
from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, captured_stdout
from django.utils import translation
-from django.utils.encoding import force_text
from django.utils.translation import ugettext
from .utils import RunInTmpDirMixin, copytree
@@ -49,7 +48,7 @@ class PoFileTests(MessageCompilationTests):
try:
call_command('compilemessages', locale=['en'], stderr=err_buffer, verbosity=0)
err = err_buffer.getvalue()
- self.assertIn("not writable location", force_text(err))
+ self.assertIn("not writable location", err)
finally:
os.chmod(mo_file_en, old_mode)
@@ -168,15 +167,15 @@ class FuzzyTranslationTest(ProjectAndAppTests):
with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]):
call_command('compilemessages', locale=[self.LOCALE], stdout=StringIO())
with translation.override(self.LOCALE):
- self.assertEqual(ugettext('Lenin'), force_text('Ленин'))
- self.assertEqual(ugettext('Vodka'), force_text('Vodka'))
+ self.assertEqual(ugettext('Lenin'), 'Ленин')
+ self.assertEqual(ugettext('Vodka'), 'Vodka')
def test_fuzzy_compiling(self):
with override_settings(LOCALE_PATHS=[os.path.join(self.test_dir, 'locale')]):
call_command('compilemessages', locale=[self.LOCALE], fuzzy=True, stdout=StringIO())
with translation.override(self.LOCALE):
- self.assertEqual(ugettext('Lenin'), force_text('Ленин'))
- self.assertEqual(ugettext('Vodka'), force_text('Водка'))
+ self.assertEqual(ugettext('Lenin'), 'Ленин')
+ self.assertEqual(ugettext('Vodka'), 'Водка')
class AppCompilationTest(ProjectAndAppTests):
diff --git a/tests/i18n/test_extraction.py b/tests/i18n/test_extraction.py
index 0adf3d0f1c..585feda3ac 100644
--- a/tests/i18n/test_extraction.py
+++ b/tests/i18n/test_extraction.py
@@ -16,7 +16,6 @@ from django.core.management.commands.makemessages import \
from django.core.management.utils import find_command
from django.test import SimpleTestCase, override_settings
from django.test.utils import captured_stderr, captured_stdout
-from django.utils.encoding import force_text
from django.utils.translation import TranslatorCommentWarning
from .utils import POFileAssertionMixin, RunInTmpDirMixin, copytree
@@ -56,7 +55,7 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase):
def _assertPoLocComment(self, assert_presence, po_filename, line_number, *comment_parts):
with open(po_filename, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
if os.name == 'nt':
# #: .\path\to\file.html:123
cwd_prefix = '%s%s' % (os.curdir, os.sep)
@@ -82,7 +81,7 @@ class ExtractorTests(POFileAssertionMixin, RunInTmpDirMixin, SimpleTestCase):
def _get_token_line_number(self, path, token):
with open(path) as f:
for line, content in enumerate(f, 1):
- if token in force_text(content):
+ if token in content:
return line
self.fail("The token '%s' could not be found in %s, please check the test config" % (token, path))
@@ -182,7 +181,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
# should not be trimmed
self.assertNotMsgId('Text with a few line breaks.', po_contents)
# should be trimmed
@@ -209,8 +208,7 @@ class BasicExtractorTests(ExtractorTests):
shutil.copyfile('./not_utf8.sample', './not_utf8.txt')
out = StringIO()
management.call_command('makemessages', locale=[LOCALE], stdout=out)
- self.assertIn("UnicodeDecodeError: skipped file not_utf8.txt in .",
- force_text(out.getvalue()))
+ self.assertIn("UnicodeDecodeError: skipped file not_utf8.txt in .", out.getvalue())
def test_unicode_file_name(self):
open(os.path.join(self.test_dir, 'vidéo.txt'), 'a').close()
@@ -221,7 +219,7 @@ class BasicExtractorTests(ExtractorTests):
shutil.copyfile('./code.sample', './code_sample.py')
out = StringIO()
management.call_command('makemessages', locale=[LOCALE], stdout=out)
- self.assertIn("code_sample.py:4", force_text(out.getvalue()))
+ self.assertIn("code_sample.py:4", out.getvalue())
def test_template_message_context_extractor(self):
"""
@@ -231,7 +229,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
# {% trans %}
self.assertIn('msgctxt "Special trans context #1"', po_contents)
self.assertMsgId("Translatable literal #7a", po_contents)
@@ -261,7 +259,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
# {% trans %}
self.assertIn('msgctxt "Context wrapped in double quotes"', po_contents)
self.assertIn('msgctxt "Context wrapped in single quotes"', po_contents)
@@ -301,7 +299,7 @@ class BasicExtractorTests(ExtractorTests):
# Now test .po file contents
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertMsgId('Translatable literal #9a', po_contents)
self.assertNotIn('ignored comment #1', po_contents)
@@ -390,7 +388,7 @@ class BasicExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=['pt_BR'], verbosity=0)
self.assertTrue(os.path.exists(BR_PO_BASE + '.po'))
with open(BR_PO_BASE + '.po', 'r', encoding='utf-8') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertMsgStr("Größe", po_contents)
@@ -492,7 +490,7 @@ class SymlinkExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], verbosity=0, symlinks=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertMsgId('This literal should be included.', po_contents)
self.assertLocationCommentPresent(self.PO_FILE, None, 'templates_symlinked', 'test.html')
else:
@@ -507,7 +505,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertIn('Plural-Forms: nplurals=2; plural=(n != 1)', po_contents)
def test_override_plural_forms(self):
@@ -528,7 +526,7 @@ class CopyPluralFormsExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], extensions=['html', 'djtpl'], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertNotIn("#-#-#-#-# django.pot (PACKAGE VERSION) #-#-#-#-#\\n", po_contents)
self.assertMsgId('First `trans`, then `blocktrans` with a plural', po_contents)
self.assertMsgIdPlural('Plural for a `trans` and `blocktrans` collision case', po_contents)
@@ -540,7 +538,7 @@ class NoWrapExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=True)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertMsgId(
'This literal should also be included wrapped or not wrapped '
'depending on the use of the --no-wrap option.',
@@ -551,7 +549,7 @@ class NoWrapExtractorTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], verbosity=0, no_wrap=False)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertMsgId(
'""\n"This literal should also be included wrapped or not '
'wrapped depending on the "\n"use of the --no-wrap option."',
@@ -583,7 +581,7 @@ class LocationCommentsTests(ExtractorTests):
management.call_command('makemessages', locale=[LOCALE], verbosity=0)
self.assertTrue(os.path.exists(self.PO_FILE))
with open(self.PO_FILE, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertMsgId('#: templates/test.html.py', po_contents)
self.assertLocationCommentNotPresent(self.PO_FILE, None, '.html.py')
self.assertLocationCommentPresent(self.PO_FILE, 5, 'templates', 'test.html')
@@ -695,11 +693,11 @@ class CustomLayoutExtractionTests(ExtractorTests):
self.assertTrue(os.path.exists(app_de_locale))
with open(project_de_locale, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertMsgId('This app has no locale directory', po_contents)
self.assertMsgId('This is a project-level string', po_contents)
with open(app_de_locale, 'r') as fp:
- po_contents = force_text(fp.read())
+ po_contents = fp.read()
self.assertMsgId('This app has a locale directory', po_contents)
diff --git a/tests/i18n/test_percents.py b/tests/i18n/test_percents.py
index 22ea73b790..bf14e020f5 100644
--- a/tests/i18n/test_percents.py
+++ b/tests/i18n/test_percents.py
@@ -2,7 +2,6 @@ import os
from django.template import Context, Template
from django.test import SimpleTestCase, override_settings
-from django.utils.encoding import force_text
from django.utils.translation import activate, get_language, trans_real
from .utils import POFileAssertionMixin
@@ -40,7 +39,7 @@ class ExtractingStringsWithPercentSigns(POFileAssertionMixin, FrenchTestCase):
def setUp(self):
super(ExtractingStringsWithPercentSigns, self).setUp()
with open(self.PO_FILE, 'r') as fp:
- self.po_contents = force_text(fp.read())
+ self.po_contents = fp.read()
def test_trans_tag_with_percent_symbol_at_the_end(self):
self.assertMsgId('Literal with a percent symbol at the end %%', self.po_contents)
diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py
index 49b1819c26..b060f7e25b 100644
--- a/tests/inspectdb/tests.py
+++ b/tests/inspectdb/tests.py
@@ -5,7 +5,6 @@ from unittest import mock, skipUnless
from django.core.management import call_command
from django.db import connection
from django.test import TestCase, skipUnlessDBFeature
-from django.utils.encoding import force_text
from .models import ColumnTypes
@@ -264,7 +263,7 @@ class InspectDBTestCase(TestCase):
with mock.patch('django.db.backends.base.introspection.BaseDatabaseIntrospection.table_names',
return_value=['nonexistent']):
call_command('inspectdb', stdout=out)
- output = force_text(out.getvalue())
+ output = out.getvalue()
self.assertIn("# Unable to inspect table 'nonexistent'", output)
# The error message depends on the backend
self.assertIn("# The error was:", output)
diff --git a/tests/managers_regress/models.py b/tests/managers_regress/models.py
index f5fd648bff..1c274d8704 100644
--- a/tests/managers_regress/models.py
+++ b/tests/managers_regress/models.py
@@ -7,7 +7,6 @@ from django.contrib.contenttypes.fields import (
)
from django.contrib.contenttypes.models import ContentType
from django.db import models
-from django.utils.encoding import force_text
class OnlyFred(models.Manager):
@@ -123,7 +122,7 @@ class RelatedModel(models.Model):
exact = models.NullBooleanField()
def __str__(self):
- return force_text(self.pk)
+ return str(self.pk)
class RelationModel(models.Model):
@@ -136,4 +135,4 @@ class RelationModel(models.Model):
gfk = GenericForeignKey(ct_field='gfk_ctype', fk_field='gfk_id')
def __str__(self):
- return force_text(self.pk)
+ return str(self.pk)
diff --git a/tests/managers_regress/tests.py b/tests/managers_regress/tests.py
index 1b3e0a1635..a05a24e597 100644
--- a/tests/managers_regress/tests.py
+++ b/tests/managers_regress/tests.py
@@ -2,7 +2,6 @@ from django.db import models
from django.template import Context, Template
from django.test import TestCase, override_settings
from django.test.utils import isolate_apps
-from django.utils.encoding import force_text
from .models import (
AbstractBase1, AbstractBase2, AbstractBase3, Child1, Child2, Child3,
@@ -148,7 +147,7 @@ class ManagersRegressionTests(TestCase):
self.assertEqual(
t.render(Context({'related': related})),
- ''.join([force_text(relation.pk)] * 3),
+ ''.join([str(relation.pk)] * 3),
)
def test_field_can_be_called_exact(self):
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index f5d7887c35..cacbcab743 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -16,7 +16,6 @@ from django.db.migrations.exceptions import (
)
from django.db.migrations.recorder import MigrationRecorder
from django.test import override_settings
-from django.utils.encoding import force_text
from .models import UnicodeModel, UnserializableModel
from .routers import TestRouter
@@ -649,7 +648,7 @@ class MakeMigrationsTests(MigrationTestBase):
self.assertTrue(os.path.exists(init_file))
with open(init_file, 'r') as fp:
- content = force_text(fp.read())
+ content = fp.read()
self.assertEqual(content, '')
# Check for existing 0001_initial.py file in migration folder
diff --git a/tests/migrations/test_graph.py b/tests/migrations/test_graph.py
index 26a5f18328..d19839405a 100644
--- a/tests/migrations/test_graph.py
+++ b/tests/migrations/test_graph.py
@@ -5,7 +5,6 @@ from django.db.migrations.exceptions import (
)
from django.db.migrations.graph import RECURSION_DEPTH_WARNING, MigrationGraph
from django.test import SimpleTestCase
-from django.utils.encoding import force_text
class GraphTests(SimpleTestCase):
@@ -395,7 +394,7 @@ class GraphTests(SimpleTestCase):
def test_stringify(self):
graph = MigrationGraph()
- self.assertEqual(force_text(graph), "Graph: 0 nodes, 0 edges")
+ self.assertEqual(str(graph), "Graph: 0 nodes, 0 edges")
graph.add_node(("app_a", "0001"), None)
graph.add_node(("app_a", "0002"), None)
@@ -406,5 +405,5 @@ class GraphTests(SimpleTestCase):
graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_a", "0002"))
graph.add_dependency("app_a.0003", ("app_a", "0003"), ("app_b", "0002"))
- self.assertEqual(force_text(graph), "Graph: 5 nodes, 3 edges")
+ self.assertEqual(str(graph), "Graph: 5 nodes, 3 edges")
self.assertEqual(repr(graph), "")
diff --git a/tests/prefetch_related/tests.py b/tests/prefetch_related/tests.py
index 33456069aa..f59a030bc7 100644
--- a/tests/prefetch_related/tests.py
+++ b/tests/prefetch_related/tests.py
@@ -5,7 +5,6 @@ from django.db.models import Prefetch, QuerySet
from django.db.models.query import get_prefetcher
from django.test import TestCase, override_settings
from django.test.utils import CaptureQueriesContext
-from django.utils.encoding import force_text
from .models import (
Author, Author2, AuthorAddress, AuthorWithAge, Bio, Book, Bookmark,
@@ -1260,7 +1259,7 @@ class Ticket21760Tests(TestCase):
def test_bug(self):
prefetcher = get_prefetcher(self.rooms[0], 'house', 'house')[0]
queryset = prefetcher.get_prefetch_queryset(list(Room.objects.all()))[0]
- self.assertNotIn(' JOIN ', force_text(queryset.query))
+ self.assertNotIn(' JOIN ', str(queryset.query))
class Ticket25546Tests(TestCase):
diff --git a/tests/sessions_tests/tests.py b/tests/sessions_tests/tests.py
index 177903b18f..54b8ac53a5 100644
--- a/tests/sessions_tests/tests.py
+++ b/tests/sessions_tests/tests.py
@@ -33,7 +33,6 @@ from django.test import (
)
from django.test.utils import patch_logger
from django.utils import timezone
-from django.utils.encoding import force_text
from .models import SessionStore as CustomDatabaseSession
@@ -388,7 +387,7 @@ class DatabaseSessionTests(SessionTestsMixin, TestCase):
session_key = self.session.session_key
s = self.model.objects.get(session_key=session_key)
- self.assertEqual(force_text(s), session_key)
+ self.assertEqual(str(s), session_key)
def test_session_get_decoded(self):
"""
diff --git a/tests/staticfiles_tests/cases.py b/tests/staticfiles_tests/cases.py
index 537fbac6a0..2305b34527 100644
--- a/tests/staticfiles_tests/cases.py
+++ b/tests/staticfiles_tests/cases.py
@@ -7,7 +7,6 @@ from django.conf import settings
from django.core.management import call_command
from django.template import Context, Template
from django.test import SimpleTestCase, override_settings
-from django.utils.encoding import force_text
from .settings import TEST_SETTINGS
@@ -20,7 +19,7 @@ class BaseStaticFilesMixin:
def assertFileContains(self, filepath, text):
self.assertIn(
text,
- self._get_file(force_text(filepath)),
+ self._get_file(filepath),
"'%s' not in '%s'" % (text, filepath),
)
diff --git a/tests/staticfiles_tests/test_management.py b/tests/staticfiles_tests/test_management.py
index a9aeb68c3a..5e1f49a5d3 100644
--- a/tests/staticfiles_tests/test_management.py
+++ b/tests/staticfiles_tests/test_management.py
@@ -18,7 +18,6 @@ from django.test import override_settings
from django.test.utils import extend_sys_path
from django.utils import timezone
from django.utils._os import symlinks_supported
-from django.utils.encoding import force_text
from django.utils.functional import empty
from .cases import CollectionTestCase, StaticFilesTestCase, TestDefaults
@@ -41,7 +40,7 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
"""
def _get_file(self, filepath):
path = call_command('findstatic', filepath, all=False, verbosity=0, stdout=StringIO())
- with codecs.open(force_text(path), "r", "utf-8") as f:
+ with codecs.open(path, "r", "utf-8") as f:
return f.read()
def test_all_files(self):
@@ -51,8 +50,8 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
result = call_command('findstatic', 'test/file.txt', verbosity=1, stdout=StringIO())
lines = [l.strip() for l in result.split('\n')]
self.assertEqual(len(lines), 3) # three because there is also the "Found here" line
- self.assertIn('project', force_text(lines[1]))
- self.assertIn('apps', force_text(lines[2]))
+ self.assertIn('project', lines[1])
+ self.assertIn('apps', lines[2])
def test_all_files_less_verbose(self):
"""
@@ -61,8 +60,8 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
result = call_command('findstatic', 'test/file.txt', verbosity=0, stdout=StringIO())
lines = [l.strip() for l in result.split('\n')]
self.assertEqual(len(lines), 2)
- self.assertIn('project', force_text(lines[0]))
- self.assertIn('apps', force_text(lines[1]))
+ self.assertIn('project', lines[0])
+ self.assertIn('apps', lines[1])
def test_all_files_more_verbose(self):
"""
@@ -71,10 +70,10 @@ class TestFindStatic(TestDefaults, CollectionTestCase):
"""
result = call_command('findstatic', 'test/file.txt', verbosity=2, stdout=StringIO())
lines = [l.strip() for l in result.split('\n')]
- self.assertIn('project', force_text(lines[1]))
- self.assertIn('apps', force_text(lines[2]))
- self.assertIn("Looking in the following locations:", force_text(lines[3]))
- searched_locations = ', '.join(force_text(x) for x in lines[4:])
+ self.assertIn('project', lines[1])
+ self.assertIn('apps', lines[2])
+ self.assertIn("Looking in the following locations:", lines[3])
+ searched_locations = ', '.join(lines[4:])
# AppDirectoriesFinder searched locations
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'test', 'static'), searched_locations)
self.assertIn(os.path.join('staticfiles_tests', 'apps', 'no_label', 'static'), searched_locations)
@@ -195,7 +194,7 @@ class TestInteractiveMessages(CollectionTestCase):
with mock.patch('builtins.input', side_effect=self.mock_input(stdout)):
call_command('collectstatic', interactive=True, clear=True, stdout=stdout)
- output = force_text(stdout.getvalue())
+ output = stdout.getvalue()
self.assertNotIn(self.overwrite_warning_msg, output)
self.assertIn(self.delete_warning_msg, output)
@@ -204,7 +203,7 @@ class TestInteractiveMessages(CollectionTestCase):
self.run_collectstatic()
with mock.patch('builtins.input', side_effect=self.mock_input(stdout)):
call_command('collectstatic', interactive=True, stdout=stdout)
- output = force_text(stdout.getvalue())
+ output = stdout.getvalue()
self.assertIn(self.overwrite_warning_msg, output)
self.assertNotIn(self.delete_warning_msg, output)
@@ -212,7 +211,7 @@ class TestInteractiveMessages(CollectionTestCase):
stdout = StringIO()
shutil.rmtree(settings.STATIC_ROOT)
call_command('collectstatic', interactive=True, stdout=stdout)
- output = force_text(stdout.getvalue())
+ output = stdout.getvalue()
self.assertNotIn(self.overwrite_warning_msg, output)
self.assertNotIn(self.delete_warning_msg, output)
self.assertIn(self.files_copied_msg, output)
@@ -223,7 +222,7 @@ class TestInteractiveMessages(CollectionTestCase):
with override_settings(STATIC_ROOT=static_dir):
call_command('collectstatic', interactive=True, stdout=stdout)
shutil.rmtree(static_dir)
- output = force_text(stdout.getvalue())
+ output = stdout.getvalue()
self.assertNotIn(self.overwrite_warning_msg, output)
self.assertNotIn(self.delete_warning_msg, output)
self.assertIn(self.files_copied_msg, output)
@@ -349,7 +348,7 @@ class TestCollectionOverwriteWarning(CollectionTestCase):
"""
out = StringIO()
call_command('collectstatic', interactive=False, verbosity=3, stdout=out, **kwargs)
- return force_text(out.getvalue())
+ return out.getvalue()
def test_no_warning(self):
"""
@@ -409,7 +408,7 @@ class TestCollectionNeverCopyStorage(CollectionTestCase):
"""
stdout = StringIO()
self.run_collectstatic(stdout=stdout, verbosity=2)
- output = force_text(stdout.getvalue())
+ output = stdout.getvalue()
self.assertIn("Skipping 'test.txt' (not modified)", output)
diff --git a/tests/staticfiles_tests/test_storage.py b/tests/staticfiles_tests/test_storage.py
index c72100ccb1..2bbe912507 100644
--- a/tests/staticfiles_tests/test_storage.py
+++ b/tests/staticfiles_tests/test_storage.py
@@ -12,7 +12,6 @@ from django.contrib.staticfiles.management.commands.collectstatic import \
from django.core.cache.backends.base import BaseCache
from django.core.management import call_command
from django.test import override_settings
-from django.utils.encoding import force_text
from .cases import CollectionTestCase
from .settings import TEST_ROOT
@@ -380,7 +379,7 @@ class TestCollectionManifestStorage(TestHashedFiles, CollectionTestCase):
manifest_content = storage.staticfiles_storage.read_manifest()
self.assertIn(
'"version": "%s"' % storage.staticfiles_storage.manifest_version,
- force_text(manifest_content)
+ manifest_content
)
def test_parse_cache(self):
diff --git a/tests/template_tests/filter_tests/test_slugify.py b/tests/template_tests/filter_tests/test_slugify.py
index cb23e9b320..b1d617f5bc 100644
--- a/tests/template_tests/filter_tests/test_slugify.py
+++ b/tests/template_tests/filter_tests/test_slugify.py
@@ -1,6 +1,5 @@
from django.template.defaultfilters import slugify
from django.test import SimpleTestCase
-from django.utils.encoding import force_text
from django.utils.functional import lazy
from django.utils.safestring import mark_safe
@@ -42,7 +41,7 @@ class FunctionTests(SimpleTestCase):
self.assertEqual(slugify(123), '123')
def test_slugify_lazy_string(self):
- lazy_str = lazy(lambda string: force_text(string), str)
+ lazy_str = lazy(lambda string: string, str)
self.assertEqual(
slugify(lazy_str(' Jack & Jill like numbers 1,2,3 and 4 and silly characters ?%.$!/')),
'jack-jill-like-numbers-123-and-4-and-silly-characters',
diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py
index 963d0a9a16..2efdd24ff8 100644
--- a/tests/utils_tests/test_encoding.py
+++ b/tests/utils_tests/test_encoding.py
@@ -24,7 +24,7 @@ class TestEncodingUtils(unittest.TestCase):
def test_force_text_lazy(self):
s = SimpleLazyObject(lambda: 'x')
- self.assertTrue(issubclass(type(force_text(s)), str))
+ self.assertTrue(type(force_text(s)), str)
def test_force_bytes_exception(self):
"""
diff --git a/tests/utils_tests/test_html.py b/tests/utils_tests/test_html.py
index c2a64699cb..3d4a6508a1 100644
--- a/tests/utils_tests/test_html.py
+++ b/tests/utils_tests/test_html.py
@@ -3,7 +3,6 @@ from datetime import datetime
from django.test import SimpleTestCase
from django.utils import html, safestring
-from django.utils.encoding import force_text
from django.utils.functional import lazystr
@@ -99,7 +98,7 @@ class TestUtilsHtml(SimpleTestCase):
for filename in ('strip_tags1.html', 'strip_tags2.txt'):
path = os.path.join(os.path.dirname(__file__), 'files', filename)
with open(path, 'r') as fp:
- content = force_text(fp.read())
+ content = fp.read()
start = datetime.now()
stripped = html.strip_tags(content)
elapsed = datetime.now() - start
@@ -173,7 +172,7 @@ class TestUtilsHtml(SimpleTestCase):
html_obj = HtmlClass()
self.assertTrue(hasattr(HtmlClass, '__html__'))
self.assertTrue(hasattr(html_obj, '__html__'))
- self.assertEqual(force_text(html_obj), html_obj.__html__())
+ self.assertEqual(str(html_obj), html_obj.__html__())
def test_html_safe_subclass(self):
class BaseClass:
@@ -191,7 +190,7 @@ class TestUtilsHtml(SimpleTestCase):
return 'some html safe content'
subclass_obj = Subclass()
- self.assertEqual(force_text(subclass_obj), subclass_obj.__html__())
+ self.assertEqual(str(subclass_obj), subclass_obj.__html__())
def test_html_safe_defines_html_error(self):
msg = "can't apply @html_safe to HtmlClass because it defines __html__()."
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index a3938ce848..dcec795f68 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -14,7 +14,7 @@ from django.template import TemplateDoesNotExist
from django.test import RequestFactory, SimpleTestCase, override_settings
from django.test.utils import LoggingCaptureMixin, patch_logger
from django.urls import reverse
-from django.utils.encoding import force_bytes, force_text
+from django.utils.encoding import force_bytes
from django.utils.functional import SimpleLazyObject
from django.views.debug import (
CLEANSED_SUBSTITUTE, CallableSettingWrapper, ExceptionReporter,
@@ -740,14 +740,14 @@ class ExceptionReportTestMixin:
email = mail.outbox[0]
# Frames vars are never shown in plain text email reports.
- body_plain = force_text(email.body)
+ body_plain = str(email.body)
self.assertNotIn('cooked_eggs', body_plain)
self.assertNotIn('scrambled', body_plain)
self.assertNotIn('sauce', body_plain)
self.assertNotIn('worcestershire', body_plain)
# Frames vars are shown in html email reports.
- body_html = force_text(email.alternatives[0][0])
+ body_html = str(email.alternatives[0][0])
self.assertIn('cooked_eggs', body_html)
self.assertIn('scrambled', body_html)
self.assertIn('sauce', body_html)
@@ -773,14 +773,14 @@ class ExceptionReportTestMixin:
email = mail.outbox[0]
# Frames vars are never shown in plain text email reports.
- body_plain = force_text(email.body)
+ body_plain = str(email.body)
self.assertNotIn('cooked_eggs', body_plain)
self.assertNotIn('scrambled', body_plain)
self.assertNotIn('sauce', body_plain)
self.assertNotIn('worcestershire', body_plain)
# Frames vars are shown in html email reports.
- body_html = force_text(email.alternatives[0][0])
+ body_html = str(email.alternatives[0][0])
self.assertIn('cooked_eggs', body_html)
self.assertIn('scrambled', body_html)
self.assertIn('sauce', body_html)
@@ -812,7 +812,7 @@ class ExceptionReportTestMixin:
self.assertEqual(len(mail.outbox), 1)
email = mail.outbox[0]
# Frames vars are never shown in plain text email reports.
- body = force_text(email.body)
+ body = str(email.body)
self.assertNotIn('cooked_eggs', body)
self.assertNotIn('scrambled', body)
self.assertNotIn('sauce', body)