summaryrefslogtreecommitdiff
path: root/tests/shortcuts
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-01-26 21:57:10 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-02-03 08:29:45 +0100
commit2133f3157eff853329bafb7fda74c3c8fb4eae42 (patch)
tree5bb262ab847c79b3f70d8a8888e267b2816b0373 /tests/shortcuts
parenta53541852d5601232899e54d66e623bc163c6dc2 (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/shortcuts')
-rw-r--r--tests/shortcuts/jinja2/shortcuts/using.html1
-rw-r--r--tests/shortcuts/templates/shortcuts/using.html1
-rw-r--r--tests/shortcuts/tests.py24
-rw-r--r--tests/shortcuts/urls.py3
-rw-r--r--tests/shortcuts/views.py17
5 files changed, 46 insertions, 0 deletions
diff --git a/tests/shortcuts/jinja2/shortcuts/using.html b/tests/shortcuts/jinja2/shortcuts/using.html
new file mode 100644
index 0000000000..8ce973e958
--- /dev/null
+++ b/tests/shortcuts/jinja2/shortcuts/using.html
@@ -0,0 +1 @@
+Jinja2
diff --git a/tests/shortcuts/templates/shortcuts/using.html b/tests/shortcuts/templates/shortcuts/using.html
new file mode 100644
index 0000000000..65bcbf65a4
--- /dev/null
+++ b/tests/shortcuts/templates/shortcuts/using.html
@@ -0,0 +1 @@
+DTL
diff --git a/tests/shortcuts/tests.py b/tests/shortcuts/tests.py
index e22cf4d386..98251244c5 100644
--- a/tests/shortcuts/tests.py
+++ b/tests/shortcuts/tests.py
@@ -1,5 +1,6 @@
from django.utils.deprecation import RemovedInDjango20Warning
from django.test import TestCase, ignore_warnings, override_settings
+from django.test.utils import require_jinja2
@override_settings(
@@ -38,6 +39,20 @@ class ShortcutTests(TestCase):
self.assertEqual(response.content, b'spam eggs\n')
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')
+ def test_render_to_response_with_status(self):
+ response = self.client.get('/render_to_response/status/')
+ self.assertEqual(response.status_code, 403)
+ self.assertEqual(response.content, b'FOO.BAR..\n')
+
+ @require_jinja2
+ def test_render_to_response_with_using(self):
+ response = self.client.get('/render_to_response/using/')
+ self.assertEqual(response.content, b'DTL\n')
+ response = self.client.get('/render_to_response/using/?using=django')
+ self.assertEqual(response.content, b'DTL\n')
+ response = self.client.get('/render_to_response/using/?using=jinja2')
+ self.assertEqual(response.content, b'Jinja2\n')
+
@ignore_warnings(category=RemovedInDjango20Warning)
def test_render_to_response_with_context_instance_misuse(self):
"""
@@ -78,6 +93,15 @@ class ShortcutTests(TestCase):
self.assertEqual(response.status_code, 403)
self.assertEqual(response.content, b'FOO.BAR../render/status/\n')
+ @require_jinja2
+ def test_render_with_using(self):
+ response = self.client.get('/render/using/')
+ self.assertEqual(response.content, b'DTL\n')
+ response = self.client.get('/render/using/?using=django')
+ self.assertEqual(response.content, b'DTL\n')
+ response = self.client.get('/render/using/?using=jinja2')
+ self.assertEqual(response.content, b'Jinja2\n')
+
@ignore_warnings(category=RemovedInDjango20Warning)
def test_render_with_current_app(self):
response = self.client.get('/render/current_app/')
diff --git a/tests/shortcuts/urls.py b/tests/shortcuts/urls.py
index cbb6c99c14..449a840f73 100644
--- a/tests/shortcuts/urls.py
+++ b/tests/shortcuts/urls.py
@@ -8,6 +8,8 @@ urlpatterns = [
url(r'^render_to_response/request_context/$', views.render_to_response_view_with_request_context),
url(r'^render_to_response/content_type/$', views.render_to_response_view_with_content_type),
url(r'^render_to_response/dirs/$', views.render_to_response_view_with_dirs),
+ url(r'^render_to_response/status/$', views.render_to_response_view_with_status),
+ url(r'^render_to_response/using/$', views.render_to_response_view_with_using),
url(r'^render_to_response/context_instance_misuse/$', views.render_to_response_with_context_instance_misuse),
url(r'^render/$', views.render_view),
url(r'^render/multiple_templates/$', views.render_view_with_multiple_templates),
@@ -15,6 +17,7 @@ urlpatterns = [
url(r'^render/content_type/$', views.render_view_with_content_type),
url(r'^render/dirs/$', views.render_with_dirs),
url(r'^render/status/$', views.render_view_with_status),
+ url(r'^render/using/$', views.render_view_with_using),
url(r'^render/current_app/$', views.render_view_with_current_app),
url(r'^render/current_app_conflict/$', views.render_view_with_current_app_conflict),
]
diff --git a/tests/shortcuts/views.py b/tests/shortcuts/views.py
index 42493f3e7b..85d1922d58 100644
--- a/tests/shortcuts/views.py
+++ b/tests/shortcuts/views.py
@@ -43,6 +43,18 @@ def render_to_response_view_with_dirs(request):
return render_to_response('render_dirs_test.html', dirs=dirs)
+def render_to_response_view_with_status(request):
+ return render_to_response('shortcuts/render_test.html', {
+ 'foo': 'FOO',
+ 'bar': 'BAR',
+ }, status=403)
+
+
+def render_to_response_view_with_using(request):
+ using = request.GET.get('using')
+ return render_to_response('shortcuts/using.html', using=using)
+
+
def context_processor(request):
return {'bar': 'context processor output'}
@@ -95,6 +107,11 @@ def render_view_with_status(request):
}, status=403)
+def render_view_with_using(request):
+ using = request.GET.get('using')
+ return render(request, 'shortcuts/using.html', using=using)
+
+
def render_view_with_current_app(request):
return render(request, 'shortcuts/render_test.html', {
'foo': 'FOO',