Ticket #12522: 12522-tests.diff
File 12522-tests.diff, 2.9 KB (added by , 14 years ago) |
---|
-
tests/regressiontests/requests/tests.py
diff --git a/tests/regressiontests/requests/tests.py b/tests/regressiontests/requests/tests.py
a b 5 5 from django.core.handlers.modpython import ModPythonRequest 6 6 from django.core.handlers.wsgi import WSGIRequest, LimitedStream 7 7 from django.http import HttpRequest, HttpResponse, parse_cookie 8 from django.test.client import MULTIPART_CONTENT, BOUNDARY, FakePayload, encode_multipart 8 9 from django.utils import unittest 9 10 from django.utils.http import cookie_date 10 11 … … 133 134 request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')}) 134 135 self.assertEqual(request.read(), 'name=value') 135 136 136 def test_read_after_ value(self):137 def test_read_after_POST(self): 137 138 """ 138 139 Reading from request is allowed after accessing request contents as 139 POST or raw_post_data.140 POST. 140 141 """ 141 142 request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')}) 142 143 self.assertEqual(request.POST, {u'name': [u'value']}) 144 self.assertEqual(request.read(), 'name=value') 145 146 def test_read_after_raw_post_data(self): 147 """ 148 Reading from request is allowed after accessing request contents as 149 raw_post_data. 150 """ 151 request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')}) 143 152 self.assertEqual(request.raw_post_data, 'name=value') 144 153 self.assertEqual(request.read(), 'name=value') 145 154 … … 156 165 def test_read_by_lines(self): 157 166 request = WSGIRequest({'REQUEST_METHOD': 'POST', 'wsgi.input': StringIO('name=value')}) 158 167 self.assertEqual(list(request), ['name=value']) 168 169 def test_POST_after_raw_post_data(self): 170 post_data = encode_multipart(BOUNDARY,dict(testkey="testvalue")) 171 env = { 172 'SERVER_PROTOCOL': 'HTTP/1.0', 173 'REQUEST_METHOD': 'POST', 174 'wsgi.input': FakePayload(post_data), 175 'CONTENT_TYPE': MULTIPART_CONTENT, 176 'CONTENT_LENGTH': len(post_data) 177 } 178 request = WSGIRequest(env) 179 nop = request.raw_post_data # Access the raw data 180 self.assertEqual(request.POST['testkey'], 'testvalue') # POST still should be accesible 181 182 def test_raw_post_data_after_POST(self): 183 post_data = encode_multipart(BOUNDARY,dict(testkey="testvalue")) 184 env = { 185 'SERVER_PROTOCOL': 'HTTP/1.0', 186 'REQUEST_METHOD': 'POST', 187 'wsgi.input': FakePayload(post_data), 188 'CONTENT_TYPE': MULTIPART_CONTENT, 189 'CONTENT_LENGTH': len(post_data) 190 } 191 request = WSGIRequest(env) 192 nop = request.POST['testkey'] # Access POST 193 self.assertEqual(len(request.raw_post_data), len(post_data)) # raw_post_data still should be accesible