Ticket #18105: 18105-1.diff

File 18105-1.diff, 4.0 KB (added by Claude Paroz, 13 years ago)

Do not accept context instance as second render_to_response parameter

  • django/contrib/auth/tests/urls.py

    diff --git a/django/contrib/auth/tests/urls.py b/django/contrib/auth/tests/urls.py
    index dbbd35e..02fd11c 100644
    a b def remote_user_auth_view(request):  
    1818
    1919def auth_processor_no_attr_access(request):
    2020    r1 = render_to_response('context_processors/auth_attrs_no_access.html',
    21         RequestContext(request, {}, processors=[context_processors.auth]))
     21        context_instance=RequestContext(request, {}, processors=[context_processors.auth]))
    2222    # *After* rendering, we check whether the session was accessed
    2323    return render_to_response('context_processors/auth_attrs_test_access.html',
    2424        {'session_accessed':request.session.accessed})
    2525
    2626def auth_processor_attr_access(request):
    2727    r1 = render_to_response('context_processors/auth_attrs_access.html',
    28         RequestContext(request, {}, processors=[context_processors.auth]))
     28        context_instance=RequestContext(request, {}, processors=[context_processors.auth]))
    2929    return render_to_response('context_processors/auth_attrs_test_access.html',
    3030        {'session_accessed':request.session.accessed})
    3131
    3232def auth_processor_user(request):
    3333    return render_to_response('context_processors/auth_attrs_user.html',
    34         RequestContext(request, {}, processors=[context_processors.auth]))
     34        context_instance=RequestContext(request, {}, processors=[context_processors.auth]))
    3535
    3636def auth_processor_perms(request):
    3737    return render_to_response('context_processors/auth_attrs_perms.html',
    38         RequestContext(request, {}, processors=[context_processors.auth]))
     38        context_instance=RequestContext(request, {}, processors=[context_processors.auth]))
    3939
    4040def auth_processor_messages(request):
    4141    info(request, "Message 1")
    4242    return render_to_response('context_processors/auth_attrs_messages.html',
    43          RequestContext(request, {}, processors=[context_processors.auth]))
     43         context_instance=RequestContext(request, {}, processors=[context_processors.auth]))
    4444
    4545def userpage(request):
    4646    pass
  • django/template/loader.py

    diff --git a/django/template/loader.py b/django/template/loader.py
    index 4185017..20f8ac9 100644
    a b def render_to_string(template_name, dictionary=None, context_instance=None):  
    163163    the templates in the list. Returns a string.
    164164    """
    165165    dictionary = dictionary or {}
     166    assert type(dictionary) is dict, "dictionary parameter must be a dictionary!"
    166167    if isinstance(template_name, (list, tuple)):
    167168        t = select_template(template_name)
    168169    else:
  • tests/regressiontests/context_processors/views.py

    diff --git a/tests/regressiontests/context_processors/views.py b/tests/regressiontests/context_processors/views.py
    index 66e7132..e6bd43f 100644
    a b from django.template.context import RequestContext  
    55
    66def request_processor(request):
    77    return render_to_response('context_processors/request_attrs.html',
    8         RequestContext(request, {}, processors=[context_processors.request]))
     8        context_instance=RequestContext(request, {}, processors=[context_processors.request]))
  • tests/regressiontests/templates/loaders.py

    diff --git a/tests/regressiontests/templates/loaders.py b/tests/regressiontests/templates/loaders.py
    index 5c11916..e7315ef 100644
    a b class RenderToStringTest(unittest.TestCase):  
    153153        self.assertRaisesRegexp(TemplateDoesNotExist,
    154154                                'No template names provided$',
    155155                                loader.select_template, [])
     156
     157    def test_bad_context_instance_position(self):
     158        """ Test that an AssertionError is raised when a Context instance is
     159            passed as the second argument of render_to_string
     160        """
     161        context = Context({'obj': 'before'})
     162        with self.assertRaises(AssertionError):
     163            loader.render_to_string('test_context.html', context)
Back to Top