diff options
author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-01-08 15:03:43 +0100 |
---|---|---|
committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-01-12 21:01:34 +0100 |
commit | a3e783fe11dd25bbf84bfb6201186566ed473506 (patch) | |
tree | 1fe6a54ab582e54f6b1f065f2236bfe2185ce254 /tests/template_backends | |
parent | 71b7668b75d10589bbbdc7c5ca9ee7a125f91c90 (diff) | |
download | django-a3e783fe11dd25bbf84bfb6201186566ed473506.tar.gz |
Deprecated passing a Context to a generic Template.render.
A deprecation path is required because the return type of
django.template.loader.get_template changed during the
multiple template engines refactor.
test_csrf_token_in_404 was incorrect: it tested the case when the
hardcoded template was rendered, and that template doesn't depend on the
CSRF token. This commit makes it test the case when a custom template is
rendered.
Diffstat (limited to 'tests/template_backends')
-rw-r--r-- | tests/template_backends/test_django.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/template_backends/test_django.py b/tests/template_backends/test_django.py index f332abbf24..2aaf6b57d8 100644 --- a/tests/template_backends/test_django.py +++ b/tests/template_backends/test_django.py @@ -1,5 +1,7 @@ +from django.template import RequestContext from django.template.backends.django import DjangoTemplates -from django.test import RequestFactory +from django.test import ignore_warnings, RequestFactory +from django.utils.deprecation import RemovedInDjango20Warning from template_tests.test_response import test_processor_name @@ -32,3 +34,20 @@ class DjangoTemplatesTests(TemplateStringsTests): # Check that context overrides context processors content = template.render({'processors': 'no'}, request) self.assertEqual(content, 'no') + + @ignore_warnings(category=RemovedInDjango20Warning) + def test_request_context_conflicts_with_request(self): + template = self.engine.from_string('hello') + + request = RequestFactory().get('/') + request_context = RequestContext(request) + # This doesn't raise an exception. + template.render(request_context, request) + + other_request = RequestFactory().get('/') + msg = ("render() was called with a RequestContext and a request " + "argument which refer to different requests. Make sure " + "that the context argument is a dict or at least that " + "the two arguments refer to the same request.") + with self.assertRaisesMessage(ValueError, msg): + template.render(request_context, other_request) |