Ticket #18356: 18356-test-client-context-lost-for-nested-views.diff

File 18356-test-client-context-lost-for-nested-views.diff, 3.4 KB (added by bmihelac, 12 years ago)
  • tests/regressiontests/test_client_regress/models.py

    From 720bd81aad14c6dae9fb952686b55bae236f7769 Mon Sep 17 00:00:00 2001
    From: Bojan Mihelac <bmihelac@mihelac.org>
    Date: Sun, 20 May 2012 17:51:17 +0200
    Subject: [PATCH] Add failing tests for #18356
    
    ---
     .../regressiontests/test_client_regress/models.py  |    8 ++++++++
     tests/regressiontests/test_client_regress/urls.py  |    1 +
     tests/regressiontests/test_client_regress/views.py |   12 ++++++++++++
     3 files changed, 21 insertions(+), 0 deletions(-)
    
    diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
    index 4f057b9..e307feb 100644
    a b class ContextTests(TestCase):  
    711711        finally:
    712712            django.template.context._standard_context_processors = None
    713713
     714    def test_nested_requests(self):
     715        """
     716        response.context is not lost when view call another view.
     717        """
     718        response = self.client.get("/test_client_regress/nested_view/")
     719        self.assertEqual(response.context.__class__, Context)
     720        self.assertEqual(response.context['nested'], 'yes')
     721
    714722
    715723@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
    716724class SessionTests(TestCase):
  • tests/regressiontests/test_client_regress/urls.py

    diff --git a/tests/regressiontests/test_client_regress/urls.py b/tests/regressiontests/test_client_regress/urls.py
    index d869c23..193d5f4 100644
    a b urlpatterns = patterns('',  
    1313    (r'^request_data/$', views.request_data),
    1414    (r'^request_data_extended/$', views.request_data, {'template':'extended.html', 'data':'bacon'}),
    1515    url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'),
     16    url(r'^nested_view/$', views.nested_view, name='nested_view'),
    1617    (r'^login_protected_redirect_view/$', views.login_protected_redirect_view),
    1718    (r'^redirects/$', RedirectView.as_view(url='/test_client_regress/redirects/further/')),
    1819    (r'^redirects/further/$', RedirectView.as_view(url='/test_client_regress/redirects/further/more/')),
  • tests/regressiontests/test_client_regress/views.py

    diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
    index ab625a9..8b71c53 100644
    a b from django.utils.encoding import smart_str  
    99from django.core.serializers.json import DjangoJSONEncoder
    1010from django.test.client import CONTENT_TYPE_RE
    1111from django.template import RequestContext
     12from django.test import Client
     13from django.test.utils import setup_test_environment
     14
    1215
    1316def no_template_view(request):
    1417    "A simple view that expects a GET request, and returns a rendered template"
    def view_with_argument(request, name):  
    5053    else:
    5154        return HttpResponse('Howdy, %s' % name)
    5255
     56def nested_view(request):
     57    """
     58    A view that uses test client to call another view.
     59    """
     60    setup_test_environment()
     61    c = Client()
     62    c.get("/test_client_regress/no_template_view")
     63    return render_to_response('base.html', {'nested':'yes'})
     64
    5365def login_protected_redirect_view(request):
    5466    "A view that redirects all requests to the GET view"
    5567    return HttpResponseRedirect('/test_client_regress/get_view/')
Back to Top