Ticket #5982: 5982-r7264.diff
File 5982-r7264.diff, 5.3 KB (added by , 17 years ago) |
---|
-
AUTHORS
296 296 serbaut@gmail.com 297 297 John Shaffer <jshaffer2112@gmail.com> 298 298 Pete Shinners <pete@shinners.org> 299 Leo Shklovskii 299 300 jason.sidabras@gmail.com 300 301 Jozko Skrablin <jozko.skrablin@gmail.com> 301 302 Ben Slavin <benjamin.slavin@gmail.com> -
django/test/client.py
1 import urllib 1 2 import sys 2 3 from cStringIO import StringIO 3 4 from django.conf import settings … … 208 209 r = { 209 210 'CONTENT_LENGTH': None, 210 211 'CONTENT_TYPE': 'text/html; charset=utf-8', 211 'PATH_INFO': path,212 'PATH_INFO': urllib.unquote(path), 212 213 'QUERY_STRING': urlencode(data, doseq=True), 213 214 'REQUEST_METHOD': 'GET', 214 215 } … … 227 228 r = { 228 229 'CONTENT_LENGTH': len(post_data), 229 230 'CONTENT_TYPE': content_type, 230 'PATH_INFO': path,231 'PATH_INFO': urllib.unquote(path), 231 232 'REQUEST_METHOD': 'POST', 232 233 'wsgi.input': StringIO(post_data), 233 234 } -
tests/regressiontests/test_client_regress/models.py
3 3 4 4 """ 5 5 from django.test import Client, TestCase 6 from django.core import mail6 from django.core.urlresolvers import reverse 7 7 import os 8 8 9 9 class AssertContainsTests(TestCase): … … 261 261 # Check that assertRedirects uses the original client, not the 262 262 # default client. 263 263 self.assertRedirects(response, "http://testserver/test_client_regress/get_view/") 264 265 266 class 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
5 5 (r'^no_template_view/$', views.no_template_view), 6 6 (r'^file_upload/$', views.file_upload_view), 7 7 (r'^get_view/$', views.get_view), 8 url(r'^arg_view/(?P<name>.+)/$', views.view_with_argument, name='arg_view'), 8 9 (r'^login_protected_redirect_view/$', views.login_protected_redirect_view) 9 10 ) -
tests/regressiontests/test_client_regress/views.py
1 1 from django.contrib.auth.decorators import login_required 2 from django.core.mail import EmailMessage, SMTPConnection3 2 from django.http import HttpResponse, HttpResponseRedirect, HttpResponseServerError 4 from django.shortcuts import render_to_response5 3 6 4 def no_template_view(request): 7 5 "A simple view that expects a GET request, and returns a rendered template" … … 20 18 return HttpResponseServerError() 21 19 22 20 def get_view(request): 23 "A simple login protected view" 21 "A simple login protected view" 24 22 return HttpResponse("Hello world") 25 23 get_view = login_required(get_view) 26 24 25 def 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 27 37 def login_protected_redirect_view(request): 28 38 "A view that redirects all requests to the GET view" 29 39 return HttpResponseRedirect('/test_client_regress/get_view/')