summaryrefslogtreecommitdiff
path: root/tests/shortcuts
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-11-22 09:22:38 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-11-22 17:58:38 +0100
commit733178830072caeca3c054a220808b4c557faec4 (patch)
tree74d0eeee1edc9f2861aea82599ab6bc63cbcd2c2 /tests/shortcuts
parentbf1bd0fbc9d4920327ad998ad11facf842492e23 (diff)
downloaddjango-733178830072caeca3c054a220808b4c557faec4.tar.gz
Avoided rewrapping Contexts in render_to_response.
This change preserves backwards-compatibility for a very common misuse of render_to_response which even occurred in the official documentation. It fixes that misuse wherever it happened in the code base and docs. Context.__init__ is documented as accepting a dict and nothing else. Since Context is dict-like, Context(Context({})) could work to some extent. However, things get complicated with RequestContext and that gets in the way of refactoring the template engine. This is the real rationale for this change.
Diffstat (limited to 'tests/shortcuts')
-rw-r--r--tests/shortcuts/tests.py9
-rw-r--r--tests/shortcuts/urls.py1
-rw-r--r--tests/shortcuts/views.py9
3 files changed, 19 insertions, 0 deletions
diff --git a/tests/shortcuts/tests.py b/tests/shortcuts/tests.py
index 4835b40797..24a73d4ffd 100644
--- a/tests/shortcuts/tests.py
+++ b/tests/shortcuts/tests.py
@@ -32,6 +32,15 @@ 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_context_instance_misuse(self):
+ """
+ For backwards-compatibility, ensure that it's possible to pass a
+ RequestContext instance in the dictionary argument instead of the
+ context_instance argument.
+ """
+ response = self.client.get('/render_to_response/context_instance_misuse/')
+ self.assertContains(response, 'context processor output')
+
def test_render(self):
response = self.client.get('/render/')
self.assertEqual(response.status_code, 200)
diff --git a/tests/shortcuts/urls.py b/tests/shortcuts/urls.py
index cd18c8a01b..f02e74a745 100644
--- a/tests/shortcuts/urls.py
+++ b/tests/shortcuts/urls.py
@@ -7,6 +7,7 @@ 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/context_instance_misuse/$', views.render_to_response_with_context_instance_misuse),
url(r'^render/$', views.render_view),
url(r'^render/base_context/$', views.render_view_with_base_context),
url(r'^render/content_type/$', views.render_view_with_content_type),
diff --git a/tests/shortcuts/views.py b/tests/shortcuts/views.py
index afae78d4d8..c75d324a34 100644
--- a/tests/shortcuts/views.py
+++ b/tests/shortcuts/views.py
@@ -33,6 +33,15 @@ def render_to_response_view_with_dirs(request):
return render_to_response('render_dirs_test.html', dirs=dirs)
+def context_processor(request):
+ return {'bar': 'context processor output'}
+
+
+def render_to_response_with_context_instance_misuse(request):
+ context_instance = RequestContext(request, {}, processors=[context_processor])
+ # Incorrect -- context_instance should be passed as a keyword argument.
+ return render_to_response('shortcuts/render_test.html', context_instance)
+
def render_view(request):
return render(request, 'shortcuts/render_test.html', {
'foo': 'FOO',