[Zope-Checkins]
SVN: Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/
integrated theuni's additional test from 2.11 (see r73132)
Andreas Jung
andreas at andreas-jung.com
Sun Jun 3 09:24:55 EDT 2007
Log message for revision 76217:
integrated theuni's additional test from 2.11 (see r73132)
Changed:
U Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/HTTPRequest.py
U Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/tests/testHTTPRequest.py
-=-
Modified: Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/HTTPRequest.py 2007-06-03 13:22:12 UTC (rev 76216)
+++ Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/HTTPRequest.py 2007-06-03 13:24:55 UTC (rev 76217)
@@ -13,7 +13,7 @@
__version__='$Revision: 1.96 $'[11:-2]
-import re, sys, os, time, random, codecs, inspect
+import re, sys, os, time, random, codecs, inspect, tempfile
from types import StringType, UnicodeType
from BaseRequest import BaseRequest, quote
from HTTPResponse import HTTPResponse
@@ -339,7 +339,6 @@
if script: script="%s/%s" % (server_url,script)
else: script=server_url
other['URL']=self.script=script
- other['method'] = environ.get('REQUEST_METHOD', 'GET').upper()
################################################################
# Cookie values should *not* be appended to existing form
@@ -395,7 +394,7 @@
taintedform=self.taintedform
meth=None
- fs=FieldStorage(fp=fp,environ=environ,keep_blank_values=1)
+ fs=ZopeFieldStorage(fp=fp,environ=environ,keep_blank_values=1)
if not hasattr(fs,'list') or fs.list is None:
# Hm, maybe it's an XML-RPC
if (fs.headers.has_key('content-type') and
@@ -1418,7 +1417,11 @@
except: pass
return dict
+class ZopeFieldStorage(FieldStorage):
+ def make_file(self, binary=None):
+ return tempfile.NamedTemporaryFile("w+b")
+
class FileUpload:
'''\
File upload objects
@@ -1443,7 +1446,7 @@
else: methods= ['close', 'fileno', 'flush', 'isatty',
'read', 'readline', 'readlines', 'seek',
'tell', 'truncate', 'write', 'writelines',
- '__iter__','next'] # see Collector 1837
+ '__iter__','next', 'name'] # see Collector 1837
d=self.__dict__
for m in methods:
Modified: Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/tests/testHTTPRequest.py
===================================================================
--- Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/tests/testHTTPRequest.py 2007-06-03 13:22:12 UTC (rev 76216)
+++ Zope/branches/Zope211-3.4-integration/lib/python/ZPublisher/tests/testHTTPRequest.py 2007-06-03 13:24:55 UTC (rev 76217)
@@ -1,8 +1,17 @@
import unittest
from urllib import quote_plus
-class AuthCredentialsTests( unittest.TestCase ):
+TEST_LARGEFILE_DATA = '''
+--12345
+Content-Disposition: form-data; name="file"; filename="file"
+Content-Type: application/octet-stream
+test %s
+
+''' % ('test' * 1000)
+
+class AuthCredentialsTestsa( unittest.TestCase ):
+
def _getTargetClass(self):
from ZPublisher.HTTPRequest import HTTPRequest
return HTTPRequest
@@ -684,6 +693,17 @@
req.close()
self.assertEqual(start_count, sys.getrefcount(s)) # The test
+ def testFileName(self):
+ # checks fileupload object supports the filename
+ from StringIO import StringIO
+ s = StringIO(TEST_LARGEFILE_DATA)
+ env = TEST_ENVIRON.copy()
+ from ZPublisher.HTTPRequest import HTTPRequest
+ req = HTTPRequest(s, env, None)
+ req.processInputs()
+ f = req.form.get('file')
+ self.assert_(f.name)
+
def testFileIterator(self):
# checks fileupload object supports the iterator protocol
# collector entry 1837
@@ -739,26 +759,7 @@
from zope.publisher.base import DebugFlags
self.assertEqual(getDebug(request), '1')
self.assert_(isinstance(getDebugFromZope3(request), DebugFlags))
-
- def testMethod(self):
- TEST_ENVIRON = {
- 'REQUEST_METHOD': 'GET',
- 'SERVER_NAME': 'localhost',
- 'SERVER_PORT': '80',
- }
- from StringIO import StringIO
- from ZPublisher.HTTPRequest import HTTPRequest
- s = StringIO('')
- env = TEST_ENVIRON.copy()
- request = HTTPRequest(s, env, None)
- self.assertEqual(request.method, 'GET')
-
- env = TEST_ENVIRON.copy()
- env['REQUEST_METHOD'] = 'post'
- request = HTTPRequest(s, env, None)
- self.assertEqual(request.method, 'POST')
-
def testTrustedProxies(self):
TEST_ENVIRON = {
'REQUEST_METHOD': 'GET',
@@ -793,7 +794,7 @@
def test_suite():
suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(AuthCredentialsTests, 'test'))
+ suite.addTest(unittest.makeSuite(AuthCredentialsTestsa, 'test'))
suite.addTest(unittest.makeSuite(RecordTests, 'test'))
suite.addTest(unittest.makeSuite(ProcessInputsTests, 'test'))
suite.addTest(unittest.makeSuite(RequestTests, 'test'))
More information about the Zope-Checkins
mailing list