Django

Code

Changeset 7330

Show
Ignore:
Timestamp:
03/20/08 01:50:54 (4 months ago)
Author:
mtredinnick
Message:

Fixed #5982 -- Changed test client's URL processing to match core's (everything
gets run through urllib.unquote()). Patch from Leo Shklovskii and Russell
Keith-Magee.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/AUTHORS

    r7325 r7330  
    312312    John Shaffer <jshaffer2112@gmail.com> 
    313313    Pete Shinners <pete@shinners.org> 
     314    Leo Shklovskii 
    314315    jason.sidabras@gmail.com 
    315316    Jozko Skrablin <jozko.skrablin@gmail.com> 
  • django/trunk/django/test/client.py

    r7131 r7330  
     1import urllib 
    12import sys 
    23from cStringIO import StringIO 
     
    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', 
     
    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), 
  • django/trunk/tests/regressiontests/test_client_regress/models.py

    r6662 r7330  
    44""" 
    55from django.test import Client, TestCase 
    6 from django.core import mail 
     6from django.core.urlresolvers import reverse 
    77import os 
    88 
     
    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 
  • django/trunk/tests/regressiontests/test_client_regress/urls.py

    r6039 r7330  
    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) 
  • django/trunk/tests/regressiontests/test_client_regress/views.py

    r6039 r7330  
    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): 
     
    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) 
     24 
     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) 
    2636 
    2737def login_protected_redirect_view(request):