summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJulien Phalip <jphalip@gmail.com>2011-10-22 09:15:50 +0000
committerJulien Phalip <jphalip@gmail.com>2011-10-22 09:15:50 +0000
commit4f00a2d316d6a8ffb6ca4ab6c89aaf8fb8bd3e60 (patch)
tree675ebfd94f11db6ea2daafbca4eedb37ea47d712 /tests
parentac88f048c909de17e57414e35bd4e8f2fa2c17c2 (diff)
Fixed #15826 -- Made `assertContains` and `assertNotContains` work with `SimpleTemplateResponse` by forcing it to be rendered if it hasn't been rendered yet. Thanks to bmihelac for the report, to mmcnickle for the initial patch and tests, and to Carl Meyer for the guidance.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17025 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/test_client_regress/models.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
index ff851971ff..b1e5bc4ff0 100644
--- a/tests/regressiontests/test_client_regress/models.py
+++ b/tests/regressiontests/test_client_regress/models.py
@@ -14,6 +14,8 @@ import django.template.context
from django.test import Client, TestCase
from django.test.client import encode_file, RequestFactory
from django.test.utils import ContextList, override_settings
+from django.template.response import SimpleTemplateResponse
+from django.http import HttpResponse
class AssertContainsTests(TestCase):
@@ -130,6 +132,37 @@ class AssertContainsTests(TestCase):
self.assertNotContains(r, u'はたけ')
self.assertNotContains(r, '\xe3\x81\xaf\xe3\x81\x9f\xe3\x81\x91'.decode('utf-8'))
+ def test_assert_contains_renders_template_response(self):
+ """ Test that we can pass in an unrendered SimpleTemplateReponse
+ without throwing an error.
+ Refs #15826.
+ """
+ response = SimpleTemplateResponse(Template('Hello'), status=200)
+ self.assertContains(response, 'Hello')
+
+ def test_assert_contains_using_non_template_response(self):
+ """ Test that auto-rendering does not affect responses that aren't
+ instances (or subclasses) of SimpleTemplateResponse.
+ Refs #15826.
+ """
+ response = HttpResponse('Hello')
+ self.assertContains(response, 'Hello')
+
+ def test_assert_not_contains_renders_template_response(self):
+ """ Test that we can pass in an unrendered SimpleTemplateReponse
+ without throwing an error.
+ Refs #15826.
+ """
+ response = SimpleTemplateResponse(Template('Hello'), status=200)
+ self.assertNotContains(response, 'Bye')
+
+ def test_assert_not_contains_using_non_template_response(self):
+ """ Test that auto-rendering does not affect responses that aren't
+ instances (or subclasses) of SimpleTemplateResponse.
+ Refs #15826.
+ """
+ response = HttpResponse('Hello')
+ self.assertNotContains(response, 'Bye')
class AssertTemplateUsedTests(TestCase):
fixtures = ['testdata.json']