Ticket #5982: 5982-r7264.diff

File 5982-r7264.diff, 5.3 KB (added by Leo Shklovskii, 17 years ago)

modified test case and patch

  • AUTHORS

     
    296296    serbaut@gmail.com
    297297    John Shaffer <jshaffer2112@gmail.com>
    298298    Pete Shinners <pete@shinners.org>
     299    Leo Shklovskii
    299300    jason.sidabras@gmail.com
    300301    Jozko Skrablin <jozko.skrablin@gmail.com>
    301302    Ben Slavin <benjamin.slavin@gmail.com>
  • django/test/client.py

     
     1import urllib
    12import sys
    23from cStringIO import StringIO
    34from django.conf import settings
     
    208209        r = {
    209210            'CONTENT_LENGTH':  None,
    210211            'CONTENT_TYPE':    'text/html; charset=utf-8',
    211             'PATH_INFO':       path,
     212            'PATH_INFO':       urllib.unquote(path),
    212213            'QUERY_STRING':    urlencode(data, doseq=True),
    213214            'REQUEST_METHOD': 'GET',
    214215        }
     
    227228        r = {
    228229            'CONTENT_LENGTH': len(post_data),
    229230            'CONTENT_TYPE':   content_type,
    230             'PATH_INFO':      path,
     231            'PATH_INFO':      urllib.unquote(path),
    231232            'REQUEST_METHOD': 'POST',
    232233            'wsgi.input':     StringIO(post_data),
    233234        }
  • tests/regressiontests/test_client_regress/models.py

     
    33
    44"""
    55from django.test import Client, TestCase
    6 from django.core import mail
     6from django.core.urlresolvers import reverse
    77import os
    88
    99class AssertContainsTests(TestCase):
     
    261261        # Check that assertRedirects uses the original client, not the
    262262        # default client.
    263263        self.assertRedirects(response, "http://testserver/test_client_regress/get_view/")
     264
     265
     266class URLEscapingTests(TestCase):
     267    def test_simple_argument_get(self):
     268        "Get a view that has a simple string argument"
     269        response = self.client.get(reverse('arg_view', args=['Slartibartfast']))
     270        self.assertEqual(response.status_code, 200)
     271        self.assertEqual(response.content, 'Howdy, Slartibartfast')
     272
     273    def test_argument_with_space_get(self):
     274        "Get a view that has a string argument that requires escaping"
     275        response = self.client.get(reverse('arg_view', args=['Arthur Dent']))
     276        self.assertEqual(response.status_code, 200)
     277        self.assertEqual(response.content, 'Hi, Arthur')
     278
     279    def test_simple_argument_post(self):
     280        "Post for a view that has a simple string argument"
     281        response = self.client.post(reverse('arg_view', args=['Slartibartfast']))
     282        self.assertEqual(response.status_code, 200)
     283        self.assertEqual(response.content, 'Howdy, Slartibartfast')
     284
     285    def test_argument_with_space_post(self):
     286        "Post for a view that has a string argument that requires escaping"
     287        response = self.client.post(reverse('arg_view', args=['Arthur Dent']))
     288        self.assertEqual(response.status_code, 200)
     289        self.assertEqual(response.content, 'Hi, Arthur')
     290
     291
  • 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)
  • tests/regressiontests/test_client_regress/views.py

     
    11from django.contrib.auth.decorators import login_required
    2 from django.core.mail import EmailMessage, SMTPConnection
    32from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError
    4 from django.shortcuts import render_to_response
    53
    64def no_template_view(request):
    75    "A simple view that expects a GET request, and returns a rendered template"
     
    2018        return HttpResponseServerError()
    2119
    2220def get_view(request):
    23     "A simple login protected view"   
     21    "A simple login protected view"
    2422    return HttpResponse("Hello world")
    2523get_view = login_required(get_view)
    2624
     25def view_with_argument(request, name):
     26    """A view that takes a string argument
     27
     28    The purpose of this view is to check that if a space is provided in
     29    the argument, the test framework unescapes the %20 before passing
     30    the value to the view.
     31    """
     32    if name == 'Arthur Dent':
     33        return HttpResponse('Hi, Arthur')
     34    else:
     35        return HttpResponse('Howdy, %s' % name)
     36
    2737def login_protected_redirect_view(request):
    2838    "A view that redirects all requests to the GET view"
    2939    return HttpResponseRedirect('/test_client_regress/get_view/')
Back to Top