Loading django/test/testcases.py +6 −0 Original line number Diff line number Diff line Loading @@ -518,6 +518,12 @@ class SimpleTestCase(unittest.TestCase): if msg_prefix: msg_prefix += ": " if template_name is not None and response is not None and not hasattr(response, 'templates'): raise ValueError( "assertTemplateUsed() and assertTemplateNotUsed() are only " "usable on responses fetched using the Django test Client." ) if not hasattr(response, 'templates') or (response is None and template_name): if response: template_name = response Loading tests/test_utils/tests.py +12 −0 Original line number Diff line number Diff line Loading @@ -385,6 +385,18 @@ class AssertTemplateUsedContextManagerTests(TestCase): with self.assertTemplateUsed('template_used/base.html'): render_to_string('template_used/alternative.html') 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): self.assertTemplateUsed(response, 'template.html') with self.assertRaisesMessage(ValueError, error_msg): self.assertTemplateNotUsed(response, 'template.html') class HTMLEqualTests(TestCase): def test_html_parser(self): Loading Loading
django/test/testcases.py +6 −0 Original line number Diff line number Diff line Loading @@ -518,6 +518,12 @@ class SimpleTestCase(unittest.TestCase): if msg_prefix: msg_prefix += ": " if template_name is not None and response is not None and not hasattr(response, 'templates'): raise ValueError( "assertTemplateUsed() and assertTemplateNotUsed() are only " "usable on responses fetched using the Django test Client." ) if not hasattr(response, 'templates') or (response is None and template_name): if response: template_name = response Loading
tests/test_utils/tests.py +12 −0 Original line number Diff line number Diff line Loading @@ -385,6 +385,18 @@ class AssertTemplateUsedContextManagerTests(TestCase): with self.assertTemplateUsed('template_used/base.html'): render_to_string('template_used/alternative.html') 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): self.assertTemplateUsed(response, 'template.html') with self.assertRaisesMessage(ValueError, error_msg): self.assertTemplateNotUsed(response, 'template.html') class HTMLEqualTests(TestCase): def test_html_parser(self): Loading