Ticket #15368: 15368_lp_tests.diff

File 15368_lp_tests.diff, 3.1 KB (added by Luke Plant, 14 years ago)

tests

  • tests/regressiontests/test_client_regress/models.py

    diff -r f38db5003acc tests/regressiontests/test_client_regress/models.py
    a b  
    99from django.core.urlresolvers import reverse
    1010from django.template import (TemplateDoesNotExist, TemplateSyntaxError,
    1111    Context, Template, loader)
     12import django.template.context
    1213from django.test import Client, TestCase
    1314from django.test.client import encode_file
    1415from django.test.utils import ContextList
     
    648649        except KeyError, e:
    649650            self.assertEquals(e.args[0], 'does-not-exist')
    650651
     652    def test_15368(self):
     653        # Need to insert a context processor that assumes certain things about
     654        # the request instance. This triggers a bug caused by some ways of
     655        # copying RequestContext.
     656        try:
     657            django.template.context._standard_context_processors = (lambda request: {'path': request.special_path},)
     658            response = self.client.get("/test_client_regress/request_context_view/")
     659            self.assertContains(response, 'Path: /test_client_regress/request_context_view/')
     660        finally:
     661            django.template.context._standard_context_processors = None
     662
    651663
    652664class SessionTests(TestCase):
    653665    fixtures = ['testdata.json']
  • new file tests/regressiontests/test_client_regress/templates/request_context.html

    diff -r f38db5003acc tests/regressiontests/test_client_regress/templates/request_context.html
    - +  
     1Path: {{ path }}
  • tests/regressiontests/test_client_regress/urls.py

    diff -r f38db5003acc tests/regressiontests/test_client_regress/urls.py
    a b  
    2727    (r'^check_headers/$', views.check_headers),
    2828    (r'^check_headers_redirect/$', redirect_to, {'url': '/test_client_regress/check_headers/'}),
    2929    (r'^raw_post_data/$', views.raw_post_data),
     30    (r'^request_context_view/$', views.request_context_view),
    3031)
  • tests/regressiontests/test_client_regress/views.py

    diff -r f38db5003acc tests/regressiontests/test_client_regress/views.py
    a b  
    77from django.utils.encoding import smart_str
    88from django.core.serializers.json import DjangoJSONEncoder
    99from django.test.client import CONTENT_TYPE_RE
     10from django.template import RequestContext
    1011
    1112def no_template_view(request):
    1213    "A simple view that expects a GET request, and returns a rendered template"
     
    9495def raw_post_data(request):
    9596    "A view that is requested with GET and accesses request.raw_post_data. Refs #14753."
    9697    return HttpResponse(request.raw_post_data)
     98
     99def request_context_view(request):
     100    # Special attribute that won't be present on a plain HttpRequest
     101    request.special_path = request.path
     102    return render_to_response('request_context.html', context_instance=RequestContext(request, {}))
Back to Top