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:
parent
d4c9dab74b
commit
f7e0bffa2e
@ -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)
|
||||
|
||||
|
@ -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 "
|
||||
|
Loading…
Reference in New Issue
Block a user