Loading AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -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> Loading django/test/client.py +3 −2 Original line number Diff line number Diff line import urllib import sys from cStringIO import StringIO from django.conf import settings Loading Loading @@ -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', } Loading @@ -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), } Loading tests/regressiontests/test_client_regress/models.py +29 −1 Original line number Diff line number Diff line Loading @@ -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): Loading Loading @@ -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') tests/regressiontests/test_client_regress/urls.py +1 −0 Original line number Diff line number Diff line Loading @@ -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) ) tests/regressiontests/test_client_regress/views.py +13 −3 Original line number Diff line number Diff line 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" Loading @@ -24,6 +22,18 @@ def get_view(request): 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 Loading
AUTHORS +1 −0 Original line number Diff line number Diff line Loading @@ -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> Loading
django/test/client.py +3 −2 Original line number Diff line number Diff line import urllib import sys from cStringIO import StringIO from django.conf import settings Loading Loading @@ -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', } Loading @@ -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), } Loading
tests/regressiontests/test_client_regress/models.py +29 −1 Original line number Diff line number Diff line Loading @@ -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): Loading Loading @@ -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')
tests/regressiontests/test_client_regress/urls.py +1 −0 Original line number Diff line number Diff line Loading @@ -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) )
tests/regressiontests/test_client_regress/views.py +13 −3 Original line number Diff line number Diff line 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" Loading @@ -24,6 +22,18 @@ def get_view(request): 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