Refs #23919 -- Removed str_prefix usage
This commit is contained in:
parent
7aba69145d
commit
289fc1bfa5
|
@ -1,6 +1,5 @@
|
|||
from django.db.models import Max
|
||||
from django.test import TestCase, skipUnlessDBFeature
|
||||
from django.test.utils import str_prefix
|
||||
|
||||
from .models import Celebrity, Fan, Staff, StaffTag, Tag
|
||||
|
||||
|
@ -78,8 +77,7 @@ class DistinctOnTests(TestCase):
|
|||
(
|
||||
(Staff.objects.distinct('id').order_by('id', 'coworkers__name').
|
||||
values_list('id', 'coworkers__name')),
|
||||
[str_prefix("(1, %(_)s'p2')"), str_prefix("(2, %(_)s'p1')"),
|
||||
str_prefix("(3, %(_)s'p1')"), "(4, None)"]
|
||||
["(1, 'p2')", "(2, 'p1')", "(3, 'p1')", "(4, None)"]
|
||||
),
|
||||
)
|
||||
for qset, expected in qsets:
|
||||
|
|
|
@ -19,7 +19,6 @@ from django.forms.utils import ErrorList
|
|||
from django.http import QueryDict
|
||||
from django.template import Context, Template
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.utils import str_prefix
|
||||
from django.utils.datastructures import MultiValueDict
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.html import format_html
|
||||
|
@ -2519,9 +2518,7 @@ Password: <input type="password" name="password" required />
|
|||
# Case 3: POST with valid data (the success message).)
|
||||
self.assertEqual(
|
||||
my_function('POST', {'username': 'adrian', 'password1': 'secret', 'password2': 'secret'}),
|
||||
str_prefix(
|
||||
"VALID: [('password1', %(_)s'secret'), ('password2', %(_)s'secret'), ('username', %(_)s'adrian')]"
|
||||
)
|
||||
"VALID: [('password1', 'secret'), ('password2', 'secret'), ('username', 'adrian')]"
|
||||
)
|
||||
|
||||
def test_templates_with_forms(self):
|
||||
|
|
|
@ -13,7 +13,7 @@ from django.http import (
|
|||
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, str_prefix
|
||||
from django.test.utils import freeze_time
|
||||
from django.utils.http import cookie_date, urlencode
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
@ -57,17 +57,17 @@ class RequestsTests(SimpleTestCase):
|
|||
request.POST = {'post-key': 'post-value'}
|
||||
request.COOKIES = {'post-key': 'post-value'}
|
||||
request.META = {'post-key': 'post-value'}
|
||||
self.assertEqual(repr(request), str_prefix("<HttpRequest: GET '/somepath/'>"))
|
||||
self.assertEqual(repr(request), "<HttpRequest: GET '/somepath/'>")
|
||||
|
||||
def test_httprequest_repr_invalid_method_and_path(self):
|
||||
request = HttpRequest()
|
||||
self.assertEqual(repr(request), str_prefix("<HttpRequest>"))
|
||||
self.assertEqual(repr(request), "<HttpRequest>")
|
||||
request = HttpRequest()
|
||||
request.method = "GET"
|
||||
self.assertEqual(repr(request), str_prefix("<HttpRequest>"))
|
||||
self.assertEqual(repr(request), "<HttpRequest>")
|
||||
request = HttpRequest()
|
||||
request.path = ""
|
||||
self.assertEqual(repr(request), str_prefix("<HttpRequest>"))
|
||||
self.assertEqual(repr(request), "<HttpRequest>")
|
||||
|
||||
def test_wsgirequest(self):
|
||||
request = WSGIRequest({
|
||||
|
@ -156,13 +156,13 @@ class RequestsTests(SimpleTestCase):
|
|||
|
||||
def test_wsgirequest_repr(self):
|
||||
request = WSGIRequest({'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
|
||||
self.assertEqual(repr(request), str_prefix("<WSGIRequest: GET '/'>"))
|
||||
self.assertEqual(repr(request), "<WSGIRequest: GET '/'>")
|
||||
request = WSGIRequest({'PATH_INFO': '/somepath/', 'REQUEST_METHOD': 'get', 'wsgi.input': BytesIO(b'')})
|
||||
request.GET = {'get-key': 'get-value'}
|
||||
request.POST = {'post-key': 'post-value'}
|
||||
request.COOKIES = {'post-key': 'post-value'}
|
||||
request.META = {'post-key': 'post-value'}
|
||||
self.assertEqual(repr(request), str_prefix("<WSGIRequest: GET '/somepath/'>"))
|
||||
self.assertEqual(repr(request), "<WSGIRequest: GET '/somepath/'>")
|
||||
|
||||
def test_wsgirequest_path_info(self):
|
||||
def wsgi_str(path_info, encoding='utf-8'):
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from django.template.defaultfilters import make_list
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.utils import str_prefix
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from ..utils import setup
|
||||
|
@ -15,22 +14,22 @@ class MakeListTests(SimpleTestCase):
|
|||
@setup({'make_list01': '{% autoescape off %}{{ a|make_list }}{% endautoescape %}'})
|
||||
def test_make_list01(self):
|
||||
output = self.engine.render_to_string('make_list01', {"a": mark_safe("&")})
|
||||
self.assertEqual(output, str_prefix("[%(_)s'&']"))
|
||||
self.assertEqual(output, "['&']")
|
||||
|
||||
@setup({'make_list02': '{{ a|make_list }}'})
|
||||
def test_make_list02(self):
|
||||
output = self.engine.render_to_string('make_list02', {"a": mark_safe("&")})
|
||||
self.assertEqual(output, str_prefix("[%(_)s'&']"))
|
||||
self.assertEqual(output, "['&']")
|
||||
|
||||
@setup({'make_list03': '{% autoescape off %}{{ a|make_list|stringformat:"s"|safe }}{% endautoescape %}'})
|
||||
def test_make_list03(self):
|
||||
output = self.engine.render_to_string('make_list03', {"a": mark_safe("&")})
|
||||
self.assertEqual(output, str_prefix("[%(_)s'&']"))
|
||||
self.assertEqual(output, "['&']")
|
||||
|
||||
@setup({'make_list04': '{{ a|make_list|stringformat:"s"|safe }}'})
|
||||
def test_make_list04(self):
|
||||
output = self.engine.render_to_string('make_list04', {"a": mark_safe("&")})
|
||||
self.assertEqual(output, str_prefix("[%(_)s'&']"))
|
||||
self.assertEqual(output, "['&']")
|
||||
|
||||
|
||||
class FunctionTests(SimpleTestCase):
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.test import (
|
|||
Client, SimpleTestCase, TestCase, modify_settings, override_settings,
|
||||
)
|
||||
from django.test.client import RedirectCycleError, RequestFactory, encode_file
|
||||
from django.test.utils import ContextList, str_prefix
|
||||
from django.test.utils import ContextList
|
||||
from django.urls import NoReverseMatch, reverse
|
||||
from django.utils.translation import ugettext_lazy
|
||||
|
||||
|
@ -595,21 +595,19 @@ class AssertFormErrorTests(SimpleTestCase):
|
|||
self.assertFormError(response, 'form', 'email', 'Some error.')
|
||||
except AssertionError as e:
|
||||
self.assertIn(
|
||||
str_prefix(
|
||||
"The field 'email' on form 'form' in context 0 does not "
|
||||
"contain the error 'Some error.' (actual errors: "
|
||||
"[%(_)s'Enter a valid email address.'])"
|
||||
), str(e)
|
||||
"['Enter a valid email address.'])",
|
||||
str(e)
|
||||
)
|
||||
try:
|
||||
self.assertFormError(response, 'form', 'email', 'Some error.', msg_prefix='abc')
|
||||
except AssertionError as e:
|
||||
self.assertIn(
|
||||
str_prefix(
|
||||
"abc: The field 'email' on form 'form' in context 0 does "
|
||||
"not contain the error 'Some error.' (actual errors: "
|
||||
"[%(_)s'Enter a valid email address.'])",
|
||||
), str(e)
|
||||
"['Enter a valid email address.'])",
|
||||
str(e)
|
||||
)
|
||||
|
||||
def test_unknown_nonfield_error(self):
|
||||
|
@ -719,10 +717,10 @@ class AssertFormsetErrorTests(SimpleTestCase):
|
|||
def test_unknown_error(self):
|
||||
"An assertion is raised if the field doesn't contain the specified error"
|
||||
for prefix, kwargs in self.msg_prefixes:
|
||||
msg = str_prefix(
|
||||
prefix + "The field 'email' on formset 'my_formset', form 0 "
|
||||
msg = prefix + (
|
||||
"The field 'email' on formset 'my_formset', form 0 "
|
||||
"in context 0 does not contain the error 'Some error.' "
|
||||
"(actual errors: [%(_)s'Enter a valid email address.'])"
|
||||
"(actual errors: ['Enter a valid email address.'])"
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
self.assertFormsetError(self.response_form_errors, 'my_formset', 0, 'email', 'Some error.', **kwargs)
|
||||
|
@ -743,10 +741,10 @@ class AssertFormsetErrorTests(SimpleTestCase):
|
|||
def test_unknown_nonfield_error(self):
|
||||
"An assertion is raised if the formsets non-field errors doesn't contain the provided error."
|
||||
for prefix, kwargs in self.msg_prefixes:
|
||||
msg = str_prefix(
|
||||
prefix + "The formset 'my_formset', form 0 in context 0 does not "
|
||||
msg = prefix + (
|
||||
"The formset 'my_formset', form 0 in context 0 does not "
|
||||
"contain the non-field error 'Some error.' (actual errors: "
|
||||
"[%(_)s'Non-field error.'])"
|
||||
"['Non-field error.'])"
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
self.assertFormsetError(self.response_form_errors, 'my_formset', 0, None, 'Some error.', **kwargs)
|
||||
|
@ -766,11 +764,10 @@ class AssertFormsetErrorTests(SimpleTestCase):
|
|||
def test_unknown_nonform_error(self):
|
||||
"An assertion is raised if the formsets non-form errors doesn't contain the provided error."
|
||||
for prefix, kwargs in self.msg_prefixes:
|
||||
msg = str_prefix(
|
||||
prefix +
|
||||
msg = prefix + (
|
||||
"The formset 'my_formset' in context 0 does not contain the "
|
||||
"non-form error 'Some error.' (actual errors: [%(_)s'Forms "
|
||||
"in a set must have distinct email addresses.'])"
|
||||
"non-form error 'Some error.' (actual errors: ['Forms in a set "
|
||||
"must have distinct email addresses.'])"
|
||||
)
|
||||
with self.assertRaisesMessage(AssertionError, msg):
|
||||
self.assertFormsetError(
|
||||
|
|
|
@ -16,7 +16,6 @@ from django.core.validators import (
|
|||
validate_unicode_slug,
|
||||
)
|
||||
from django.test import SimpleTestCase
|
||||
from django.test.utils import str_prefix
|
||||
|
||||
try:
|
||||
from PIL import Image # noqa
|
||||
|
@ -314,18 +313,18 @@ def create_simple_test_method(validator, expected, value, num):
|
|||
class TestSimpleValidators(SimpleTestCase):
|
||||
def test_single_message(self):
|
||||
v = ValidationError('Not Valid')
|
||||
self.assertEqual(str(v), str_prefix("[%(_)s'Not Valid']"))
|
||||
self.assertEqual(repr(v), str_prefix("ValidationError([%(_)s'Not Valid'])"))
|
||||
self.assertEqual(str(v), "['Not Valid']")
|
||||
self.assertEqual(repr(v), "ValidationError(['Not Valid'])")
|
||||
|
||||
def test_message_list(self):
|
||||
v = ValidationError(['First Problem', 'Second Problem'])
|
||||
self.assertEqual(str(v), str_prefix("[%(_)s'First Problem', %(_)s'Second Problem']"))
|
||||
self.assertEqual(repr(v), str_prefix("ValidationError([%(_)s'First Problem', %(_)s'Second Problem'])"))
|
||||
self.assertEqual(str(v), "['First Problem', 'Second Problem']")
|
||||
self.assertEqual(repr(v), "ValidationError(['First Problem', 'Second Problem'])")
|
||||
|
||||
def test_message_dict(self):
|
||||
v = ValidationError({'first': ['First Problem']})
|
||||
self.assertEqual(str(v), str_prefix("{%(_)s'first': [%(_)s'First Problem']}"))
|
||||
self.assertEqual(repr(v), str_prefix("ValidationError({%(_)s'first': [%(_)s'First Problem']})"))
|
||||
self.assertEqual(str(v), "{'first': ['First Problem']}")
|
||||
self.assertEqual(repr(v), "ValidationError({'first': ['First Problem']})")
|
||||
|
||||
def test_regex_validator_flags(self):
|
||||
with self.assertRaises(TypeError):
|
||||
|
|
Loading…
Reference in New Issue