Refs #25969 -- Replaced usage of render_to_response() with render() in tests.
This commit is contained in:
parent
312fc1af7b
commit
edf3b88f1a
|
@ -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,
|
||||
|
@ -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')
|
||||
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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