diff --git a/tests/test_client/views.py b/tests/test_client/views.py index a4cc5cd3a7..2761f19e80 100644 --- a/tests/test_client/views.py +++ b/tests/test_client/views.py @@ -9,7 +9,7 @@ from django.http import ( HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed, HttpResponseNotFound, HttpResponseRedirect, ) -from django.shortcuts import render_to_response +from django.shortcuts import render from django.template import Context, Template from django.test import Client from django.utils.decorators import method_decorator @@ -168,12 +168,10 @@ def form_view_with_template(request): else: form = TestForm() message = 'GET form page' - return render_to_response('form_view.html', - { - 'form': form, - 'message': message - } - ) + return render(request, 'form_view.html', { + 'form': form, + 'message': message, + }) class BaseTestFormSet(BaseFormSet): diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py index 5897efa4bb..d12087078a 100644 --- a/tests/test_client_regress/tests.py +++ b/tests/test_client_regress/tests.py @@ -12,7 +12,9 @@ from django.contrib.auth.models import User from django.contrib.auth.signals import user_logged_in, user_logged_out from django.core.urlresolvers import NoReverseMatch, reverse from django.http import HttpResponse -from django.template import Context, TemplateSyntaxError, engines +from django.template import ( + Context, RequestContext, TemplateSyntaxError, engines, +) from django.template.response import SimpleTemplateResponse from django.test import ( Client, SimpleTestCase, TestCase, ignore_warnings, override_settings, @@ -1021,7 +1023,7 @@ class ContextTests(TestDataMixin, TestCase): def test_single_context(self): "Context variables can be retrieved from a single context" response = self.client.get("/request_data/", data={'foo': 'whiz'}) - self.assertEqual(response.context.__class__, Context) + self.assertIsInstance(response.context, RequestContext) self.assertIn('get-foo', response.context) self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['data'], 'sausage') @@ -1083,7 +1085,7 @@ class ContextTests(TestDataMixin, TestCase): response.context is not lost when view call another view. """ response = self.client.get("/nested_view/") - self.assertEqual(response.context.__class__, Context) + self.assertIsInstance(response.context, RequestContext) self.assertEqual(response.context['nested'], 'yes') diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py index 8470bb9935..abbf7e16fc 100644 --- a/tests/test_client_regress/views.py +++ b/tests/test_client_regress/views.py @@ -4,7 +4,7 @@ from django.conf import settings from django.contrib.auth.decorators import login_required from django.core.serializers.json import DjangoJSONEncoder from django.http import HttpResponse, HttpResponseRedirect, JsonResponse -from django.shortcuts import render, render_to_response +from django.shortcuts import render from django.template.loader import render_to_string from django.test import Client from django.test.client import CONTENT_TYPE_RE @@ -37,7 +37,7 @@ get_view = login_required(get_view) def request_data(request, template='base.html', data='sausage'): "A simple view that returns the request data in the context" - return render_to_response(template, { + return render(request, template, { 'get-foo': request.GET.get('foo'), 'get-bar': request.GET.get('bar'), 'post-foo': request.POST.get('foo'), @@ -66,7 +66,7 @@ def nested_view(request): setup_test_environment() c = Client() c.get("/no_template_view/") - return render_to_response('base.html', {'nested': 'yes'}) + return render(request, 'base.html', {'nested': 'yes'}) def login_protected_redirect_view(request): @@ -98,7 +98,7 @@ def request_methods_view(request): def return_unicode(request): - return render_to_response('unicode.html') + return render(request, 'unicode.html') def return_undecodable_binary(request): diff --git a/tests/view_tests/views.py b/tests/view_tests/views.py index 7996193b2e..a30aa21c0d 100644 --- a/tests/view_tests/views.py +++ b/tests/view_tests/views.py @@ -8,7 +8,7 @@ import sys from django.core.exceptions import PermissionDenied, SuspiciousOperation from django.core.urlresolvers import get_resolver from django.http import Http404, HttpResponse, JsonResponse -from django.shortcuts import render, render_to_response +from django.shortcuts import render from django.template import TemplateDoesNotExist from django.views.debug import ( SafeExceptionReporterFilter, technical_500_response, @@ -74,23 +74,22 @@ def view_exception(request, n): def template_exception(request, n): - return render_to_response('debug/template_exception.html', - {'arg': except_args[int(n)]}) + return render(request, 'debug/template_exception.html', {'arg': except_args[int(n)]}) def jsi18n(request): - return render_to_response('jsi18n.html') + return render(request, 'jsi18n.html') def jsi18n_multi_catalogs(request): - return render_to_response('jsi18n-multi-catalogs.html') + return render(render, 'jsi18n-multi-catalogs.html') def raises_template_does_not_exist(request, path='i_dont_exist.html'): # We need to inspect the HTML generated by the fancy 500 debug view but # the test client ignores it, so we send it explicitly. try: - return render_to_response(path) + return render(request, path) except TemplateDoesNotExist: return technical_500_response(request, *sys.exc_info())