summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-20 06:50:54 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-03-20 06:50:54 +0000
commit597f9d61050ee15df807bda6a7d9a0ff5def9774 (patch)
treea1cd14312dc2d7a62a24a5bad718ddaa606d5b57 /tests
parent9e47cc2e518cf14a55845b65007fabe8a6b00da7 (diff)
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
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/test_client_regress/models.py30
-rw-r--r--tests/regressiontests/test_client_regress/urls.py1
-rw-r--r--tests/regressiontests/test_client_regress/views.py16
3 files changed, 43 insertions, 4 deletions
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
index b5d9ae63b9..305ccc9aa3 100644
--- a/tests/regressiontests/test_client_regress/models.py
+++ b/tests/regressiontests/test_client_regress/models.py
@@ -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')
+
+
diff --git a/tests/regressiontests/test_client_regress/urls.py b/tests/regressiontests/test_client_regress/urls.py
index e771707f61..d3304caef0 100644
--- a/tests/regressiontests/test_client_regress/urls.py
+++ b/tests/regressiontests/test_client_regress/urls.py
@@ -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)
)
diff --git a/tests/regressiontests/test_client_regress/views.py b/tests/regressiontests/test_client_regress/views.py
index 75efd212e1..f44757dc10 100644
--- a/tests/regressiontests/test_client_regress/views.py
+++ b/tests/regressiontests/test_client_regress/views.py
@@ -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/')