diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2014-12-14 10:17:18 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2014-12-28 17:02:29 +0100 |
| commit | fdbfc98003f0ba2d3a12def63a75560791f3602d (patch) | |
| tree | 0238fba169970595f1a8c44d53550fada6236b4f /tests | |
| parent | a0141f9eac03f0fef722e757253bbc939c018f77 (diff) | |
Deprecated some arguments of django.shortcuts.render(_to_response).
dictionary and context_instance and superseded by context.
Refactored tests that relied context_instance with more modern idioms.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/context_processors/tests.py | 12 | ||||
| -rw-r--r-- | tests/context_processors/views.py | 16 | ||||
| -rw-r--r-- | tests/shortcuts/tests.py | 20 | ||||
| -rw-r--r-- | tests/test_client_regress/tests.py | 20 |
4 files changed, 41 insertions, 27 deletions
diff --git a/tests/context_processors/tests.py b/tests/context_processors/tests.py index 8d58f5c695..7a0d8220a8 100644 --- a/tests/context_processors/tests.py +++ b/tests/context_processors/tests.py @@ -4,7 +4,10 @@ Tests for Django's bundled context processors. from django.test import TestCase, override_settings -@override_settings(ROOT_URLCONF='context_processors.urls') +@override_settings( + ROOT_URLCONF='context_processors.urls', + TEMPLATE_CONTEXT_PROCESSORS=('django.template.context_processors.request',), +) class RequestContextProcessorTests(TestCase): """ Tests for the ``django.template.context_processors.request`` processor. @@ -35,7 +38,12 @@ class RequestContextProcessorTests(TestCase): self.assertContains(response, url) -@override_settings(ROOT_URLCONF='context_processors.urls', DEBUG=True, INTERNAL_IPS=('127.0.0.1',)) +@override_settings( + DEBUG=True, + INTERNAL_IPS=('127.0.0.1',), + ROOT_URLCONF='context_processors.urls', + TEMPLATE_CONTEXT_PROCESSORS=('django.template.context_processors.debug',), +) class DebugContextProcessorTests(TestCase): """ Tests for the ``django.template.context_processors.debug`` processor. diff --git a/tests/context_processors/views.py b/tests/context_processors/views.py index 913877f20a..1a7eda0b16 100644 --- a/tests/context_processors/views.py +++ b/tests/context_processors/views.py @@ -1,20 +1,12 @@ -from django.shortcuts import render_to_response -from django.template import context_processors -from django.template.context import RequestContext +from django.shortcuts import render from .models import DebugObject def request_processor(request): - return render_to_response( - 'context_processors/request_attrs.html', - context_instance=RequestContext(request, {}, processors=[context_processors.request])) + return render(request, 'context_processors/request_attrs.html') def debug_processor(request): - - return render_to_response( - 'context_processors/debug.html', - context_instance=RequestContext(request, { - 'debug_objects': DebugObject.objects, - }, processors=[context_processors.debug])) + context = {'debug_objects': DebugObject.objects} + return render(request, 'context_processors/debug.html', context) diff --git a/tests/shortcuts/tests.py b/tests/shortcuts/tests.py index 029c150644..429738b22f 100644 --- a/tests/shortcuts/tests.py +++ b/tests/shortcuts/tests.py @@ -17,7 +17,9 @@ class ShortcutTests(TestCase): self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') def test_render_to_response_with_request_context(self): - response = self.client.get('/render_to_response/request_context/') + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=RemovedInDjango20Warning) + response = self.client.get('/render_to_response/request_context/') self.assertEqual(response.status_code, 200) self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n') self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') @@ -42,7 +44,9 @@ class ShortcutTests(TestCase): RequestContext instance in the dictionary argument instead of the context_instance argument. """ - response = self.client.get('/render_to_response/context_instance_misuse/') + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=RemovedInDjango20Warning) + response = self.client.get('/render_to_response/context_instance_misuse/') self.assertContains(response, 'context processor output') def test_render(self): @@ -53,7 +57,9 @@ class ShortcutTests(TestCase): self.assertEqual(response.context.current_app, None) def test_render_with_base_context(self): - response = self.client.get('/render/base_context/') + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=RemovedInDjango20Warning) + response = self.client.get('/render/base_context/') self.assertEqual(response.status_code, 200) self.assertEqual(response.content, b'FOO.BAR..\n') self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8') @@ -70,7 +76,9 @@ class ShortcutTests(TestCase): self.assertEqual(response.content, b'FOO.BAR../path/to/static/media/\n') def test_render_with_current_app(self): - response = self.client.get('/render/current_app/') + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=RemovedInDjango20Warning) + response = self.client.get('/render/current_app/') self.assertEqual(response.context.current_app, "foobar_app") def test_render_with_dirs(self): @@ -83,4 +91,6 @@ class ShortcutTests(TestCase): def test_render_with_current_app_conflict(self): with self.assertRaises(ValueError): - self.client.get('/render/current_app_conflict/') + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=RemovedInDjango20Warning) + self.client.get('/render/current_app_conflict/') diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index 0d63ee9429..8bd4ad44aa 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -6,6 +6,7 @@ from __future__ import unicode_literals import os import itertools +import warnings from django.core.urlresolvers import reverse, NoReverseMatch from django.template import TemplateSyntaxError, Context, Template @@ -14,6 +15,7 @@ from django.test.client import RedirectCycleError, RequestFactory, encode_file from django.test.utils import ContextList, str_prefix from django.template.response import SimpleTemplateResponse from django.utils._os import upath +from django.utils.deprecation import RemovedInDjango20Warning from django.utils.translation import ugettext_lazy from django.http import HttpResponse from django.contrib.auth.signals import user_logged_out, user_logged_in @@ -999,14 +1001,16 @@ class ContextTests(TestCase): l.keys()) def test_15368(self): - # Need to insert a context processor that assumes certain things about - # the request instance. This triggers a bug caused by some ways of - # copying RequestContext. - with self.settings(TEMPLATE_CONTEXT_PROCESSORS=( - 'test_client_regress.context_processors.special', - )): - response = self.client.get("/request_context_view/") - self.assertContains(response, 'Path: /request_context_view/') + with warnings.catch_warnings(): + warnings.filterwarnings("ignore", category=RemovedInDjango20Warning) + # Need to insert a context processor that assumes certain things about + # the request instance. This triggers a bug caused by some ways of + # copying RequestContext. + with self.settings(TEMPLATE_CONTEXT_PROCESSORS=( + 'test_client_regress.context_processors.special', + )): + response = self.client.get("/request_context_view/") + self.assertContains(response, 'Path: /request_context_view/') def test_nested_requests(self): """ |
