mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Refs #33301 -- Made SimpleTestCase.assertFormError()/assertFormsetErrors() raise ValueError for non test client responses.
This commit is contained in:
parent
68144f4049
commit
9ac92b1efc
2 changed files with 40 additions and 16 deletions
|
@ -558,14 +558,10 @@ class AssertTemplateUsedContextManagerTests(SimpleTestCase):
|
|||
|
||||
def test_assert_used_on_http_response(self):
|
||||
response = HttpResponse()
|
||||
error_msg = (
|
||||
'assertTemplateUsed() and assertTemplateNotUsed() are only '
|
||||
'usable on responses fetched using the Django test Client.'
|
||||
)
|
||||
with self.assertRaisesMessage(ValueError, error_msg):
|
||||
msg = '%s() is only usable on responses fetched using the Django test Client.'
|
||||
with self.assertRaisesMessage(ValueError, msg % 'assertTemplateUsed'):
|
||||
self.assertTemplateUsed(response, 'template.html')
|
||||
|
||||
with self.assertRaisesMessage(ValueError, error_msg):
|
||||
with self.assertRaisesMessage(ValueError, msg % 'assertTemplateNotUsed'):
|
||||
self.assertTemplateNotUsed(response, 'template.html')
|
||||
|
||||
|
||||
|
@ -1288,6 +1284,15 @@ class TestFormset(formset_factory(TestForm)):
|
|||
|
||||
|
||||
class AssertFormErrorTests(SimpleTestCase):
|
||||
def test_non_client_response(self):
|
||||
msg = (
|
||||
'assertFormError() is only usable on responses fetched using the '
|
||||
'Django test Client.'
|
||||
)
|
||||
response = HttpResponse()
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
self.assertFormError(response, 'formset', 0, 'field', 'invalid value')
|
||||
|
||||
def test_response_with_no_context(self):
|
||||
msg = 'Response did not use any contexts to render the response'
|
||||
response = mock.Mock(context=[])
|
||||
|
@ -1384,6 +1389,15 @@ class AssertFormsetErrorTests(SimpleTestCase):
|
|||
'form-0-field': field_value,
|
||||
}
|
||||
|
||||
def test_non_client_response(self):
|
||||
msg = (
|
||||
'assertFormsetError() is only usable on responses fetched using '
|
||||
'the Django test Client.'
|
||||
)
|
||||
response = HttpResponse()
|
||||
with self.assertRaisesMessage(ValueError, msg):
|
||||
self.assertFormsetError(response, 'formset', 0, 'field', 'invalid value')
|
||||
|
||||
def test_response_with_no_context(self):
|
||||
msg = 'Response did not use any contexts to render the response'
|
||||
response = mock.Mock(context=[])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue