diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-01-26 21:57:10 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-02-03 08:32:14 +0100 |
| commit | f87457a4604efc862381020b47f4e6fe8272ac0b (patch) | |
| tree | 66681e1ff62fcf8c577570b1c9242d5d9a97a346 /tests/template_tests | |
| parent | 3af1e7860e0160bd126bdafebf8511b1ea365af9 (diff) | |
[1.8.x] Fixed #24168 -- Allowed selecting a template engine in a few APIs.
Specifically in rendering shortcuts, template responses, and class-based
views that return template responses.
Also added a test for render_to_response(status=...) which was missing
from fdbfc980.
Thanks Tim and Carl for the review.
Backport of 2133f31 from master.
Conflicts:
docs/topics/http/shortcuts.txt
tests/generic_views/test_base.py
Diffstat (limited to 'tests/template_tests')
| -rw-r--r-- | tests/template_tests/jinja2/template_tests/using.html | 1 | ||||
| -rw-r--r-- | tests/template_tests/templates/template_tests/using.html | 1 | ||||
| -rw-r--r-- | tests/template_tests/test_response.py | 20 |
3 files changed, 22 insertions, 0 deletions
diff --git a/tests/template_tests/jinja2/template_tests/using.html b/tests/template_tests/jinja2/template_tests/using.html new file mode 100644 index 0000000000..8ce973e958 --- /dev/null +++ b/tests/template_tests/jinja2/template_tests/using.html @@ -0,0 +1 @@ +Jinja2 diff --git a/tests/template_tests/templates/template_tests/using.html b/tests/template_tests/templates/template_tests/using.html new file mode 100644 index 0000000000..65bcbf65a4 --- /dev/null +++ b/tests/template_tests/templates/template_tests/using.html @@ -0,0 +1 @@ +DTL diff --git a/tests/template_tests/test_response.py b/tests/template_tests/test_response.py index 993b2002c8..3807789e63 100644 --- a/tests/template_tests/test_response.py +++ b/tests/template_tests/test_response.py @@ -11,6 +11,7 @@ from django.template import Context, engines from django.template.response import (TemplateResponse, SimpleTemplateResponse, ContentNotRenderedError) from django.test import ignore_warnings, override_settings +from django.test.utils import require_jinja2 from django.utils._os import upath from django.utils.deprecation import RemovedInDjango20Warning @@ -133,6 +134,15 @@ class SimpleTemplateResponseTest(SimpleTestCase): self.assertEqual(response['content-type'], 'application/json') self.assertEqual(response.status_code, 504) + @require_jinja2 + def test_using(self): + response = SimpleTemplateResponse('template_tests/using.html').render() + self.assertEqual(response.content, b'DTL\n') + response = SimpleTemplateResponse('template_tests/using.html', using='django').render() + self.assertEqual(response.content, b'DTL\n') + response = SimpleTemplateResponse('template_tests/using.html', using='jinja2').render() + self.assertEqual(response.content, b'Jinja2\n') + def test_post_callbacks(self): "Rendering a template response triggers the post-render callbacks" post = [] @@ -260,6 +270,16 @@ class TemplateResponseTest(SimpleTestCase): self.assertEqual(response['content-type'], 'application/json') self.assertEqual(response.status_code, 504) + @require_jinja2 + def test_using(self): + request = self.factory.get('/') + response = TemplateResponse(request, 'template_tests/using.html').render() + self.assertEqual(response.content, b'DTL\n') + response = TemplateResponse(request, 'template_tests/using.html', using='django').render() + self.assertEqual(response.content, b'DTL\n') + response = TemplateResponse(request, 'template_tests/using.html', using='jinja2').render() + self.assertEqual(response.content, b'Jinja2\n') + @ignore_warnings(category=RemovedInDjango20Warning) def test_custom_app(self): self._response('{{ foo }}', current_app="foobar") |
