Ticket #5982: 5982-r7023.diff

File 5982-r7023.diff, 2.8 KB (added by Russell Keith-Magee, 17 years ago)

Test case for bug, against r7023

  • tests/regressiontests/test_client_regress/views.py

     
    2424    return HttpResponse("Hello world")
    2525get_view = login_required(get_view)
    2626
     27def view_with_argument(request, name):
     28    """A view that takes a string argument
     29   
     30    The purpose of this view is to check that if a space is provided in
     31    the argument, the test framework unescapes the %20 before passing
     32    the value to the view.
     33    """
     34    if name == 'Arthur Dent':
     35            return HttpResponse('Hi, Arthur')
     36    else:
     37            return HttpResponse('Howdy, %s' % name)
     38               
    2739def login_protected_redirect_view(request):
    2840    "A view that redirects all requests to the GET view"
    2941    return HttpResponseRedirect('/test_client_regress/get_view/')
  • tests/regressiontests/test_client_regress/models.py

     
    44"""
    55from django.test import Client, TestCase
    66from django.core import mail
     7from django.core.urlresolvers import reverse
    78import os
    89
    910class AssertContainsTests(TestCase):
     
    261262        # Check that assertRedirects uses the original client, not the
    262263        # default client.
    263264        self.assertRedirects(response, "http://testserver/test_client_regress/get_view/")
     265
     266
     267class URLEscapingTests(TestCase):
     268    def test_simple_argument(self):
     269        "Get a view that has a simple string argument"
     270        response = self.client.get(reverse('arg_view', args=['Slartibartfast']))
     271        self.assertEqual(response.status_code, 200)
     272        self.assertEqual(response.content, 'Howdy, Slartibartfast')
     273
     274    def test_argument_with_space(self):
     275        "Get a view that has a string argument that requires escaping"
     276        response = self.client.get(reverse('arg_view', args=['Arthur Dent']))
     277        self.assertEqual(response.status_code, 200)
     278        self.assertEqual(response.content, 'Hi, Arthur')
     279       
     280 No newline at end of file
  • tests/regressiontests/test_client_regress/urls.py

     
    55    (r'^no_template_view/$', views.no_template_view),
    66    (r'^file_upload/$', views.file_upload_view),
    77    (r'^get_view/$', views.get_view),
     8    url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'),
    89    (r'^login_protected_redirect_view/$', views.login_protected_redirect_view)
    910)
Back to Top