[1.9.x] Refs #25969 -- Replaced usage of render_to_response() with render() in tests.
Backport of edf3b88f1a
from master
This commit is contained in:
parent
91c976b64b
commit
2f205e073b
|
@ -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):
|
||||
|
|
|
@ -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,
|
||||
|
@ -1023,7 +1025,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')
|
||||
|
@ -1086,7 +1088,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')
|
||||
|
||||
|
||||
|
|
|
@ -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_to_response
|
||||
from django.shortcuts import render
|
||||
from django.template import RequestContext
|
||||
from django.template.loader import render_to_string
|
||||
from django.test import Client
|
||||
|
@ -38,7 +38,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'),
|
||||
|
@ -67,7 +67,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):
|
||||
|
@ -99,7 +99,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):
|
||||
|
@ -152,7 +152,7 @@ def read_buffer(request):
|
|||
def request_context_view(request):
|
||||
# Special attribute that won't be present on a plain HttpRequest
|
||||
request.special_path = request.path
|
||||
return render_to_response('request_context.html', context_instance=RequestContext(request, {}))
|
||||
return render(request, 'request_context.html')
|
||||
|
||||
|
||||
def render_template_multiple_times(request):
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
Loading…
Reference in New Issue