1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Refs #33348 -- Made SimpleTestCase.assertFormError() raise ValueError when "field" is passed without "form_index".

This commit is contained in:
Baptiste Mispelon 2022-02-15 10:28:26 +01:00 committed by Mariusz Felisiak
parent d4c9dab74b
commit f7e0bffa2e
2 changed files with 15 additions and 0 deletions

View File

@ -658,6 +658,10 @@ class SimpleTestCase(unittest.TestCase):
stacklevel=2,
)
errors = []
if form_index is None and field is not None:
raise ValueError("You must use field=None with form_index=None.")
# Put error(s) into a list to simplify processing.
errors = to_list(errors)

View File

@ -1603,6 +1603,17 @@ class AssertFormsetErrorTests(SimpleTestCase):
)
self.assertFormsetError(response, "formset", None, None, "error")
def test_non_form_errors_with_field(self):
response = mock.Mock(
context=[
{},
{"formset": TestFormset.invalid(nonform=True)},
]
)
msg = "You must use field=None with form_index=None."
with self.assertRaisesMessage(ValueError, msg):
self.assertFormsetError(response, "formset", None, "field", "error")
def test_form_index_too_big(self):
msg = (
"The formset <TestFormset: bound=True valid=False total_forms=1> only has "