mirror of https://github.com/django/django.git
Refs #33348 -- Fixed SimpleTestCase.assertFormError() error message raised for unbound forms.
This commit is contained in:
parent
d84cd91e90
commit
d4c9dab74b
|
@ -566,7 +566,7 @@ class SimpleTestCase(unittest.TestCase):
|
||||||
def _assert_form_error(self, form, field, errors, msg_prefix, form_repr):
|
def _assert_form_error(self, form, field, errors, msg_prefix, form_repr):
|
||||||
if not form.is_bound:
|
if not form.is_bound:
|
||||||
self.fail(
|
self.fail(
|
||||||
f"{msg_prefix} The {form_repr} is not bound, it will never have any "
|
f"{msg_prefix}The {form_repr} is not bound, it will never have any "
|
||||||
f"errors."
|
f"errors."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1448,6 +1448,9 @@ class AssertFormErrorTests(SimpleTestCase):
|
||||||
response = mock.Mock(context=[{"form": TestForm()}])
|
response = mock.Mock(context=[{"form": TestForm()}])
|
||||||
with self.assertRaisesMessage(AssertionError, msg):
|
with self.assertRaisesMessage(AssertionError, msg):
|
||||||
self.assertFormError(response, "form", "field", [])
|
self.assertFormError(response, "form", "field", [])
|
||||||
|
msg_prefix = "Custom prefix"
|
||||||
|
with self.assertRaisesMessage(AssertionError, f"{msg_prefix}: {msg}"):
|
||||||
|
self.assertFormError(response, "form", "field", [], msg_prefix=msg_prefix)
|
||||||
|
|
||||||
def test_empty_errors_valid_form(self):
|
def test_empty_errors_valid_form(self):
|
||||||
response = mock.Mock(context=[{"form": TestForm.valid()}])
|
response = mock.Mock(context=[{"form": TestForm.valid()}])
|
||||||
|
|
Loading…
Reference in New Issue