Ticket #15762: patch_test_client_wsgi_input.diff
File patch_test_client_wsgi_input.diff, 3.7 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/test_client_regress/views.py
96 96 "A view that is requested with GET and accesses request.raw_post_data. Refs #14753." 97 97 return HttpResponse(request.raw_post_data) 98 98 99 def read_limited_stream(request): 100 "A view that is requested with PUT and accesses request.read(LARGE_BUFFER)." 101 return HttpResponse(request.read(99999)) 102 99 103 def request_context_view(request): 100 104 # Special attribute that won't be present on a plain HttpRequest 101 105 request.special_path = request.path -
tests/regressiontests/test_client_regress/models.py
908 908 response = self.client.get("/test_client_regress/raw_post_data/") 909 909 except AssertionError: 910 910 self.fail("Accessing request.raw_post_data from a view fetched with GET by the test client shouldn't fail.") 911 912 class ReadLimitedStreamTest(TestCase): 913 """ 914 Attempting to read beyond META["CONTENT_LENGTH"] from the test client 915 should simply return the full content of the request. 916 """ 917 def test_read_limited_stream(self): 918 try: 919 response = self.client.put("/test_client_regress/read_limited_stream/", data={'foo':'whiz'}) 920 except AssertionError: 921 self.fail("Reading more than META['CONTENT_LENGTH'] of data from a view fetched with PUT by the test client " + 922 "shouldn't fail, it should simply return the full content of the request.") -
tests/regressiontests/test_client_regress/urls.py
27 27 (r'^check_headers/$', views.check_headers), 28 28 (r'^check_headers_redirect/$', RedirectView.as_view(url='/test_client_regress/check_headers/')), 29 29 (r'^raw_post_data/$', views.raw_post_data), 30 (r'^read_limited_stream/$', views.read_limited_stream), 30 31 (r'^request_context_view/$', views.request_context_view), 31 32 ) -
django/test/client.py
26 26 from django.utils.itercompat import is_iterable 27 27 from django.db import transaction, close_connection 28 28 from django.test.utils import ContextList 29 import socket 29 30 30 31 __all__ = ('Client', 'RequestFactory', 'encode_file', 'encode_multipart') 31 32 … … 34 35 MULTIPART_CONTENT = 'multipart/form-data; boundary=%s' % BOUNDARY 35 36 CONTENT_TYPE_RE = re.compile('.*; charset=([\w\d-]+);?') 36 37 37 class FakePayload( object):38 class FakePayload(socket._fileobject): 38 39 """ 39 40 A wrapper around StringIO that restricts what can be read since data from 40 41 the network can't be seeked and cannot be read outside of its content 41 42 length. This makes sure that views can't do anything under the test client 42 43 that wouldn't work in Real Life. 44 45 We fake this up as a socket._fileobject, so that the WSGIrequest wraps it 46 up in a LimitedStream as it would do for any WSGI stream that hasn't 47 already defined it's own .read()/.readlines() implementations. 43 48 """ 44 49 def __init__(self, content): 45 50 self.__content = StringIO(content)