Ticket #15596: ticket15596.diff
File ticket15596.diff, 10.6 KB (added by , 14 years ago) |
---|
-
django/http/__init__.py
diff --git a/django/http/__init__.py b/django/http/__init__.py index 74a5afa..de71f68 100644
a b class HttpRequest(object): 257 257 258 258 def _load_post_and_files(self): 259 259 # Populates self._post and self._files 260 if self.method != 'POST':260 if self.method not in ('POST', 'PUT'): 261 261 self._post, self._files = QueryDict('', encoding=self._encoding), MultiValueDict() 262 262 return 263 263 if self._read_started: -
django/test/client.py
diff --git a/django/test/client.py b/django/test/client.py index dd0d811..e5e7f0e 100644
a b class RequestFactory(object): 214 214 else: 215 215 return urllib.unquote(parsed[2]) 216 216 217 def get(self, path, data={}, **extra):217 def _getlike_request(self, method, path, data={}, **extra): 218 218 "Construct a GET request" 219 219 220 220 parsed = urlparse(path) … … class RequestFactory(object): 222 222 'CONTENT_TYPE': 'text/html; charset=utf-8', 223 223 'PATH_INFO': self._get_path(parsed), 224 224 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4], 225 'REQUEST_METHOD': 'GET',225 'REQUEST_METHOD': method, 226 226 'wsgi.input': FakePayload('') 227 227 } 228 228 r.update(extra) 229 229 return self.request(**r) 230 230 231 def post(self, path, data={}, content_type=MULTIPART_CONTENT, 232 **extra): 233 "Construct a POST request." 231 def get(self, *args, **kwargs): 232 return self._getlike_request("GET", *args, **kwargs) 233 234 def head(self, *args, **kwargs): 235 return self._getlike_request("HEAD", *args, **kwargs) 236 237 def options(self, *args, **kwargs): 238 return self._getlike_request("OPTIONS", *args, **kwargs) 239 240 def delete(self, *args, **kwargs): 241 return self._getlike_request("DELETE", *args, **kwargs) 234 242 243 def _postlike_request(self, method, path, data={}, content_type=MULTIPART_CONTENT, **extra): 235 244 if content_type is MULTIPART_CONTENT: 236 245 post_data = encode_multipart(BOUNDARY, data) 237 246 else: … … class RequestFactory(object): 249 258 'CONTENT_TYPE': content_type, 250 259 'PATH_INFO': self._get_path(parsed), 251 260 'QUERY_STRING': parsed[4], 252 'REQUEST_METHOD': 'POST', 253 'wsgi.input': FakePayload(post_data), 254 } 255 r.update(extra) 256 return self.request(**r) 257 258 def head(self, path, data={}, **extra): 259 "Construct a HEAD request." 260 261 parsed = urlparse(path) 262 r = { 263 'CONTENT_TYPE': 'text/html; charset=utf-8', 264 'PATH_INFO': self._get_path(parsed), 265 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4], 266 'REQUEST_METHOD': 'HEAD', 267 'wsgi.input': FakePayload('') 268 } 269 r.update(extra) 270 return self.request(**r) 271 272 def options(self, path, data={}, **extra): 273 "Constrict an OPTIONS request" 274 275 parsed = urlparse(path) 276 r = { 277 'PATH_INFO': self._get_path(parsed), 278 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4], 279 'REQUEST_METHOD': 'OPTIONS', 280 'wsgi.input': FakePayload('') 281 } 282 r.update(extra) 283 return self.request(**r) 284 285 def put(self, path, data={}, content_type=MULTIPART_CONTENT, 286 **extra): 287 "Construct a PUT request." 288 289 if content_type is MULTIPART_CONTENT: 290 post_data = encode_multipart(BOUNDARY, data) 291 else: 292 post_data = data 293 294 # Make `data` into a querystring only if it's not already a string. If 295 # it is a string, we'll assume that the caller has already encoded it. 296 query_string = None 297 if not isinstance(data, basestring): 298 query_string = urlencode(data, doseq=True) 299 300 parsed = urlparse(path) 301 r = { 302 'CONTENT_LENGTH': len(post_data), 303 'CONTENT_TYPE': content_type, 304 'PATH_INFO': self._get_path(parsed), 305 'QUERY_STRING': query_string or parsed[4], 306 'REQUEST_METHOD': 'PUT', 261 'REQUEST_METHOD': method, 307 262 'wsgi.input': FakePayload(post_data), 308 263 } 309 264 r.update(extra) 310 265 return self.request(**r) 311 266 312 def delete(self, path, data={}, **extra):313 "Construct a DELETE request."267 def post(self, *args, **kwargs): 268 return self._postlike_request("POST", *args, **kwargs) 314 269 315 parsed = urlparse(path) 316 r = { 317 'PATH_INFO': self._get_path(parsed), 318 'QUERY_STRING': urlencode(data, doseq=True) or parsed[4], 319 'REQUEST_METHOD': 'DELETE', 320 'wsgi.input': FakePayload('') 321 } 322 r.update(extra) 323 return self.request(**r) 270 def put(self, *args, **kwargs): 271 return self._postlike_request("PUT", *args, **kwargs) 324 272 325 273 326 274 class Client(RequestFactory): -
tests/modeltests/test_client/models.py
diff --git a/tests/modeltests/test_client/models.py b/tests/modeltests/test_client/models.py index 0960929..a4789fb 100644
a b rather than the HTML rendered to the end-user. 23 23 from django.conf import settings 24 24 from django.core import mail 25 25 from django.test import Client, TestCase, RequestFactory 26 from django.utils import unittest 26 27 27 28 from views import get_view 28 29 … … class ClientTest(TestCase): 445 446 self.assertEqual(mail.outbox[1].to[0], 'second@example.com') 446 447 self.assertEqual(mail.outbox[1].to[1], 'third@example.com') 447 448 449 448 450 class CSRFEnabledClientTests(TestCase): 449 451 def setUp(self): 450 452 # Enable the CSRF middleware for this test … … class RequestFactoryTest(TestCase): 487 489 response = get_view(request) 488 490 489 491 self.assertEqual(response.status_code, 200) 490 self.assertContains(response, 'This is a test') 492 self.assertContains(response, 'This is a test') 493 No newline at end of file -
tests/regressiontests/generic_views/edit.py
diff --git a/tests/regressiontests/generic_views/edit.py b/tests/regressiontests/generic_views/edit.py index 923578d..9fdfe83 100644
a b class UpdateViewTests(TestCase): 111 111 self.assertRedirects(res, 'http://testserver/list/authors/') 112 112 self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe (xkcd)>']) 113 113 114 @expectedFailure115 114 def test_update_put(self): 116 115 a = Author.objects.create( 117 116 name='Randall Munroe', -
tests/regressiontests/test_client_regress/models.py
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py index 8f39961..9ebf3d2 100644
a b class RequestMethodStringDataTests(TestCase): 744 744 745 745 class QueryStringTests(TestCase): 746 746 def test_get_like_requests(self): 747 for method_name in ('get','head','options',' put','delete'):747 for method_name in ('get','head','options','delete'): 748 748 # A GET-like request can pass a query string as data 749 749 method = getattr(self.client, method_name) 750 750 response = method("/test_client_regress/request_data/", data={'foo':'whiz'}) … … class QueryStringTests(TestCase): 768 768 self.assertEqual(response.context['request-bar'], 'bang') 769 769 770 770 def test_post_like_requests(self): 771 # A POST-like request can pass a query string as data 772 response = self.client.post("/test_client_regress/request_data/", data={'foo':'whiz'}) 773 self.assertEqual(response.context['get-foo'], None) 774 self.assertEqual(response.context['post-foo'], 'whiz') 771 for method_name in ('post', 'put'): 772 # A POST-like request can pass a query string as data 773 method = getattr(self.client, method_name) 774 response = method("/test_client_regress/request_data/", data={'foo':'whiz'}) 775 self.assertEqual(response.context['get-foo'], None) 776 self.assertEqual(response.context['post-foo'], 'whiz') 775 777 776 # A POST-like request can pass a query string as part of the URL777 response = self.client.post("/test_client_regress/request_data/?foo=whiz")778 self.assertEqual(response.context['get-foo'], 'whiz')779 self.assertEqual(response.context['post-foo'], None)780 self.assertEqual(response.context['request-foo'], 'whiz')778 # A POST-like request can pass a query string as part of the URL 779 response = method("/test_client_regress/request_data/?foo=whiz") 780 self.assertEqual(response.context['get-foo'], 'whiz') 781 self.assertEqual(response.context['post-foo'], None) 782 self.assertEqual(response.context['request-foo'], 'whiz') 781 783 782 # POST data provided in the URL augments actual form data783 response = self.client.post("/test_client_regress/request_data/?foo=whiz", data={'foo':'bang'})784 self.assertEqual(response.context['get-foo'], 'whiz')785 self.assertEqual(response.context['post-foo'], 'bang')786 self.assertEqual(response.context['request-foo'], 'bang')784 # POST data provided in the URL augments actual form data 785 response = method("/test_client_regress/request_data/?foo=whiz", data={'foo':'bang'}) 786 self.assertEqual(response.context['get-foo'], 'whiz') 787 self.assertEqual(response.context['post-foo'], 'bang') 788 self.assertEqual(response.context['request-foo'], 'bang') 787 789 788 response = self.client.post("/test_client_regress/request_data/?foo=whiz", data={'bar':'bang'})789 self.assertEqual(response.context['get-foo'], 'whiz')790 self.assertEqual(response.context['get-bar'], None)791 self.assertEqual(response.context['post-foo'], None)792 self.assertEqual(response.context['post-bar'], 'bang')793 self.assertEqual(response.context['request-foo'], 'whiz')794 self.assertEqual(response.context['request-bar'], 'bang')790 response = method("/test_client_regress/request_data/?foo=whiz", data={'bar':'bang'}) 791 self.assertEqual(response.context['get-foo'], 'whiz') 792 self.assertEqual(response.context['get-bar'], None) 793 self.assertEqual(response.context['post-foo'], None) 794 self.assertEqual(response.context['post-bar'], 'bang') 795 self.assertEqual(response.context['request-foo'], 'whiz') 796 self.assertEqual(response.context['request-bar'], 'bang') 795 797 796 798 class UnicodePayloadTests(TestCase): 797 799 def test_simple_unicode_payload(self):