| 1 | from django.test import TestCase |
| 2 | |
| 3 | from django.http import HttpResponse |
| 4 | from django.template.response import SimpleTemplateResponse |
| 5 | from django.template import Template |
| 6 | |
| 7 | class TestCaseTests(TestCase): |
| 8 | |
| 9 | def test_assert_contains_renders_template_response(self): |
| 10 | """ Test that we can pass in an unrendered SimpleTemplateReponse |
| 11 | without throwing an error. |
| 12 | """ |
| 13 | response = SimpleTemplateResponse(Template('Hello'), status=200) |
| 14 | self.assertContains(response, 'Hello') |
| 15 | |
| 16 | def test_assert_contains_using_non_template_response(self): |
| 17 | """ Test that auto-rendering does not affect responses that aren't |
| 18 | instances (or subclasses) of SimpleTemplateResponse. |
| 19 | """ |
| 20 | response = HttpResponse('Hello') |
| 21 | self.assertContains(response, 'Hello') |
| 22 | |
| 23 | def test_assert_not_contains_renders_template_response(self): |
| 24 | """ Test that we can pass in an unrendered SimpleTemplateReponse |
| 25 | without throwing an error. |
| 26 | """ |
| 27 | response = SimpleTemplateResponse(Template('Hello'), status=200) |
| 28 | self.assertNotContains(response, 'Bye') |
| 29 | |
| 30 | def test_assert_not_contains_using_non_template_response(self): |
| 31 | """ Test that auto-rendering does not affect responses that aren't |
| 32 | instances (or subclasses) of SimpleTemplateResponse. |
| 33 | """ |
| 34 | response = HttpResponse('Hello') |
| 35 | self.assertNotContains(response, 'Bye') |