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. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7330 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9e47cc2e51
commit
597f9d6105
1
AUTHORS
1
AUTHORS
|
@ -311,6 +311,7 @@ answer newbie questions, and generally made Django that much better:
|
|||
serbaut@gmail.com
|
||||
John Shaffer <jshaffer2112@gmail.com>
|
||||
Pete Shinners <pete@shinners.org>
|
||||
Leo Shklovskii
|
||||
jason.sidabras@gmail.com
|
||||
Jozko Skrablin <jozko.skrablin@gmail.com>
|
||||
Ben Slavin <benjamin.slavin@gmail.com>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import urllib
|
||||
import sys
|
||||
from cStringIO import StringIO
|
||||
from django.conf import settings
|
||||
|
@ -208,7 +209,7 @@ class Client:
|
|||
r = {
|
||||
'CONTENT_LENGTH': None,
|
||||
'CONTENT_TYPE': 'text/html; charset=utf-8',
|
||||
'PATH_INFO': path,
|
||||
'PATH_INFO': urllib.unquote(path),
|
||||
'QUERY_STRING': urlencode(data, doseq=True),
|
||||
'REQUEST_METHOD': 'GET',
|
||||
}
|
||||
|
@ -227,7 +228,7 @@ class Client:
|
|||
r = {
|
||||
'CONTENT_LENGTH': len(post_data),
|
||||
'CONTENT_TYPE': content_type,
|
||||
'PATH_INFO': path,
|
||||
'PATH_INFO': urllib.unquote(path),
|
||||
'REQUEST_METHOD': 'POST',
|
||||
'wsgi.input': StringIO(post_data),
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ Regression tests for the Test Client, especially the customized assertions.
|
|||
|
||||
"""
|
||||
from django.test import Client, TestCase
|
||||
from django.core import mail
|
||||
from django.core.urlresolvers import reverse
|
||||
import os
|
||||
|
||||
class AssertContainsTests(TestCase):
|
||||
|
@ -261,3 +261,31 @@ class LoginTests(TestCase):
|
|||
# Check that assertRedirects uses the original client, not the
|
||||
# default client.
|
||||
self.assertRedirects(response, "http://testserver/test_client_regress/get_view/")
|
||||
|
||||
|
||||
class URLEscapingTests(TestCase):
|
||||
def test_simple_argument_get(self):
|
||||
"Get a view that has a simple string argument"
|
||||
response = self.client.get(reverse('arg_view', args=['Slartibartfast']))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.content, 'Howdy, Slartibartfast')
|
||||
|
||||
def test_argument_with_space_get(self):
|
||||
"Get a view that has a string argument that requires escaping"
|
||||
response = self.client.get(reverse('arg_view', args=['Arthur Dent']))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.content, 'Hi, Arthur')
|
||||
|
||||
def test_simple_argument_post(self):
|
||||
"Post for a view that has a simple string argument"
|
||||
response = self.client.post(reverse('arg_view', args=['Slartibartfast']))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.content, 'Howdy, Slartibartfast')
|
||||
|
||||
def test_argument_with_space_post(self):
|
||||
"Post for a view that has a string argument that requires escaping"
|
||||
response = self.client.post(reverse('arg_view', args=['Arthur Dent']))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response.content, 'Hi, Arthur')
|
||||
|
||||
|
||||
|
|
|
@ -5,5 +5,6 @@ urlpatterns = patterns('',
|
|||
(r'^no_template_view/$', views.no_template_view),
|
||||
(r'^file_upload/$', views.file_upload_view),
|
||||
(r'^get_view/$', views.get_view),
|
||||
url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'),
|
||||
(r'^login_protected_redirect_view/$', views.login_protected_redirect_view)
|
||||
)
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
from django.contrib.auth.decorators import login_required
|
||||
from django.core.mail import EmailMessage, SMTPConnection
|
||||
from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError
|
||||
from django.shortcuts import render_to_response
|
||||
|
||||
def no_template_view(request):
|
||||
"A simple view that expects a GET request, and returns a rendered template"
|
||||
|
@ -20,10 +18,22 @@ def file_upload_view(request):
|
|||
return HttpResponseServerError()
|
||||
|
||||
def get_view(request):
|
||||
"A simple login protected view"
|
||||
"A simple login protected view"
|
||||
return HttpResponse("Hello world")
|
||||
get_view = login_required(get_view)
|
||||
|
||||
def view_with_argument(request, name):
|
||||
"""A view that takes a string argument
|
||||
|
||||
The purpose of this view is to check that if a space is provided in
|
||||
the argument, the test framework unescapes the %20 before passing
|
||||
the value to the view.
|
||||
"""
|
||||
if name == 'Arthur Dent':
|
||||
return HttpResponse('Hi, Arthur')
|
||||
else:
|
||||
return HttpResponse('Howdy, %s' % name)
|
||||
|
||||
def login_protected_redirect_view(request):
|
||||
"A view that redirects all requests to the GET view"
|
||||
return HttpResponseRedirect('/test_client_regress/get_view/')
|
||||
|
|
Loading…
Reference in New Issue