summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-02-22 14:05:53 -0500
committerTim Graham <timograham@gmail.com>2016-02-22 17:07:07 -0500
commit3fedfc452fa94f8a6c9a64289d00202313ceb564 (patch)
tree6dd0d4aff262bb1385ca336cd8bd621d1ee6d714 /tests
parent174811c5538c8c0b8f66089b31686e80d2bc7d3b (diff)
[1.9.x] Fixed #26253 -- Fixed crashing deprecation shims in SimpleTemplateResponse.
Thanks David Reitter for the report and initial patch.
Diffstat (limited to 'tests')
-rw-r--r--tests/template_tests/test_response_deprecations.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/template_tests/test_response_deprecations.py b/tests/template_tests/test_response_deprecations.py
new file mode 100644
index 0000000000..dd95a37318
--- /dev/null
+++ b/tests/template_tests/test_response_deprecations.py
@@ -0,0 +1,42 @@
+import warnings
+
+from django.http import HttpRequest
+from django.template import Template
+from django.template.response import TemplateResponse
+from django.test import SimpleTestCase
+
+
+class MyTemplateResponse(TemplateResponse):
+ def resolve_template(self, template_name):
+ return Template(template_name)
+
+
+class DeprecationTests(SimpleTestCase):
+
+ def test_template_response(self):
+ msg = (
+ "TemplateResponse's template argument cannot be a "
+ "django.template.Template anymore. It may be a backend-specific "
+ "template like those created by get_template()."
+ )
+ with warnings.catch_warnings(record=True) as warns:
+ warnings.simplefilter('always')
+ response = TemplateResponse(HttpRequest(), Template('foo'))
+ response.render()
+ self.assertEqual(response.content, b'foo')
+ self.assertEqual(len(warns), 1)
+ self.assertEqual(str(warns[0].message), msg)
+
+ def test_custom_template_response(self):
+ response = MyTemplateResponse(HttpRequest(), 'baz')
+ msg = (
+ "MyTemplateResponse.resolve_template() must return a "
+ "backend-specific template like those created by get_template(), "
+ "not a Template."
+ )
+ with warnings.catch_warnings(record=True) as warns:
+ warnings.simplefilter('always')
+ response.render()
+ self.assertEqual(response.content, b'baz')
+ self.assertEqual(len(warns), 1)
+ self.assertEqual(str(warns[0].message), msg)