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:29:45 +0100 |
| commit | 2133f3157eff853329bafb7fda74c3c8fb4eae42 (patch) | |
| tree | 5bb262ab847c79b3f70d8a8888e267b2816b0373 /tests/template_tests | |
| parent | a53541852d5601232899e54d66e623bc163c6dc2 (diff) | |
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.
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") |
