Refs #25969 -- Replaced usage of render_to_response() with render() in tests.

This commit is contained in:
Tim Graham 2015-12-22 13:50:16 -05:00
parent 312fc1af7b
commit edf3b88f1a
4 changed files with 19 additions and 20 deletions

View File

@ -9,7 +9,7 @@ from django.http import (
HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed, HttpResponse, HttpResponseBadRequest, HttpResponseNotAllowed,
HttpResponseNotFound, HttpResponseRedirect, HttpResponseNotFound, HttpResponseRedirect,
) )
from django.shortcuts import render_to_response from django.shortcuts import render
from django.template import Context, Template from django.template import Context, Template
from django.test import Client from django.test import Client
from django.utils.decorators import method_decorator from django.utils.decorators import method_decorator
@ -168,12 +168,10 @@ def form_view_with_template(request):
else: else:
form = TestForm() form = TestForm()
message = 'GET form page' message = 'GET form page'
return render_to_response('form_view.html', return render(request, 'form_view.html', {
{
'form': form, 'form': form,
'message': message 'message': message,
} })
)
class BaseTestFormSet(BaseFormSet): class BaseTestFormSet(BaseFormSet):

View File

@ -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.contrib.auth.signals import user_logged_in, user_logged_out
from django.core.urlresolvers import NoReverseMatch, reverse from django.core.urlresolvers import NoReverseMatch, reverse
from django.http import HttpResponse 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.template.response import SimpleTemplateResponse
from django.test import ( from django.test import (
Client, SimpleTestCase, TestCase, ignore_warnings, override_settings, Client, SimpleTestCase, TestCase, ignore_warnings, override_settings,
@ -1021,7 +1023,7 @@ class ContextTests(TestDataMixin, TestCase):
def test_single_context(self): def test_single_context(self):
"Context variables can be retrieved from a single context" "Context variables can be retrieved from a single context"
response = self.client.get("/request_data/", data={'foo': 'whiz'}) 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.assertIn('get-foo', response.context)
self.assertEqual(response.context['get-foo'], 'whiz') self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['data'], 'sausage') 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.context is not lost when view call another view.
""" """
response = self.client.get("/nested_view/") response = self.client.get("/nested_view/")
self.assertEqual(response.context.__class__, Context) self.assertIsInstance(response.context, RequestContext)
self.assertEqual(response.context['nested'], 'yes') self.assertEqual(response.context['nested'], 'yes')

View File

@ -4,7 +4,7 @@ from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.core.serializers.json import DjangoJSONEncoder from django.core.serializers.json import DjangoJSONEncoder
from django.http import HttpResponse, HttpResponseRedirect, JsonResponse 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.template.loader import render_to_string
from django.test import Client from django.test import Client
from django.test.client import CONTENT_TYPE_RE 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'): def request_data(request, template='base.html', data='sausage'):
"A simple view that returns the request data in the context" "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-foo': request.GET.get('foo'),
'get-bar': request.GET.get('bar'), 'get-bar': request.GET.get('bar'),
'post-foo': request.POST.get('foo'), 'post-foo': request.POST.get('foo'),
@ -66,7 +66,7 @@ def nested_view(request):
setup_test_environment() setup_test_environment()
c = Client() c = Client()
c.get("/no_template_view/") 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): def login_protected_redirect_view(request):
@ -98,7 +98,7 @@ def request_methods_view(request):
def return_unicode(request): def return_unicode(request):
return render_to_response('unicode.html') return render(request, 'unicode.html')
def return_undecodable_binary(request): def return_undecodable_binary(request):

View File

@ -8,7 +8,7 @@ import sys
from django.core.exceptions import PermissionDenied, SuspiciousOperation from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.core.urlresolvers import get_resolver from django.core.urlresolvers import get_resolver
from django.http import Http404, HttpResponse, JsonResponse 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.template import TemplateDoesNotExist
from django.views.debug import ( from django.views.debug import (
SafeExceptionReporterFilter, technical_500_response, SafeExceptionReporterFilter, technical_500_response,
@ -74,23 +74,22 @@ def view_exception(request, n):
def template_exception(request, n): def template_exception(request, n):
return render_to_response('debug/template_exception.html', return render(request, 'debug/template_exception.html', {'arg': except_args[int(n)]})
{'arg': except_args[int(n)]})
def jsi18n(request): def jsi18n(request):
return render_to_response('jsi18n.html') return render(request, 'jsi18n.html')
def jsi18n_multi_catalogs(request): 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'): 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 # We need to inspect the HTML generated by the fancy 500 debug view but
# the test client ignores it, so we send it explicitly. # the test client ignores it, so we send it explicitly.
try: try:
return render_to_response(path) return render(request, path)
except TemplateDoesNotExist: except TemplateDoesNotExist:
return technical_500_response(request, *sys.exc_info()) return technical_500_response(request, *sys.exc_info())