[Zope-Checkins]
SVN: Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py
cleanup
Philipp von Weitershausen
philikon at philikon.de
Sun Jul 29 11:22:18 EDT 2007
Log message for revision 78462:
cleanup
Changed:
U Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py
-=-
Modified: Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py
===================================================================
--- Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py 2007-07-29 15:11:41 UTC (rev 78461)
+++ Zope/branches/philikon-aq/lib/python/ZPublisher/tests/testHTTPRequest.py 2007-07-29 15:22:17 UTC (rev 78462)
@@ -1,6 +1,15 @@
+import sys
+import base64
import unittest
from urllib import quote_plus
-
+from types import ListType, TupleType, StringType, UnicodeType
+from StringIO import StringIO
+
+from DateTime import DateTime
+from ZPublisher.HTTPRequest import HTTPRequest, record, trusted_proxies
+from ZPublisher.TaintedString import TaintedString
+from ZPublisher.Converters import type_converters
+
TEST_LARGEFILE_DATA = '''
--12345
Content-Disposition: form-data; name="file"; filename="file"
@@ -13,13 +22,10 @@
class AuthCredentialsTests( unittest.TestCase ):
def _getTargetClass(self):
- from ZPublisher.HTTPRequest import HTTPRequest
return HTTPRequest
def _makeOne(self, stdin=None, environ=None, response=None, clean=1):
-
if stdin is None:
- from StringIO import StringIO
stdin = StringIO()
if environ is None:
@@ -40,9 +46,6 @@
return self._getTargetClass()(stdin, environ, response, clean)
def test__authUserPW_simple( self ):
-
- import base64
-
user_id = 'user'
password = 'password'
encoded = base64.encodestring( '%s:%s' % ( user_id, password ) )
@@ -57,11 +60,7 @@
self.assertEqual( password_x, password )
def test__authUserPW_with_embedded_colon( self ):
-
# http://www.zope.org/Collectors/Zope/2039
-
- import base64
-
user_id = 'user'
password = 'embedded:colon'
encoded = base64.encodestring( '%s:%s' % ( user_id, password ) )
@@ -75,21 +74,20 @@
self.assertEqual( user_id_x, user_id )
self.assertEqual( password_x, password )
-class RecordTests( unittest.TestCase ):
- def test_repr( self ):
- from ZPublisher.HTTPRequest import record
- record = record()
- record.a = 1
- record.b = 'foo'
- r = repr( record )
- d = eval( r )
- self.assertEqual( d, record.__dict__ )
+class RecordTests(unittest.TestCase):
+ def test_repr(self):
+ rec = record()
+ rec.a = 1
+ rec.b = 'foo'
+ r = repr(rec)
+ d = eval(r)
+ self.assertEqual(d, rec.__dict__)
+
class ProcessInputsTests(unittest.TestCase):
def _getHTTPRequest(self, env):
- from ZPublisher.HTTPRequest import HTTPRequest
return HTTPRequest(None, env, None)
def _processInputs(self, inputs):
@@ -119,9 +117,6 @@
# when one is found.
# Also raises an Assertion if a string which *should* have been
# tainted is found, or when a tainted string is not deemed dangerous.
- from types import ListType, TupleType, StringType, UnicodeType
- from ZPublisher.HTTPRequest import record
- from ZPublisher.TaintedString import TaintedString
retval = 0
@@ -199,8 +194,6 @@
self._onlyTaintedformHoldsTaintedStrings(req)
def testSimpleMarshalling(self):
- from DateTime import DateTime
-
inputs = (
('num:int', '42'), ('fract:float', '4.2'), ('bign:long', '45'),
('words:string', 'Some words'), ('2tokens:tokens', 'one two'),
@@ -454,9 +447,6 @@
self._onlyTaintedformHoldsTaintedStrings(req)
def testSimpleContainersWithTaints(self):
- from types import ListType, TupleType
- from ZPublisher.HTTPRequest import record
-
inputs = (
('toneitem:list', '<one>'),
('<tkeyoneitem>:list', 'one'),
@@ -611,8 +601,6 @@
def testNoTaintedExceptions(self):
# Feed tainted garbage to the conversion methods, and any exception
# returned should be HTML safe
- from ZPublisher.Converters import type_converters
- from DateTime import DateTime
for type, convert in type_converters.items():
try:
convert('<html garbage>')
@@ -695,12 +683,10 @@
def testRemoveStdinReferences(self):
# Verifies that all references to the input stream go away on
# request.close(). Otherwise a tempfile may stick around.
- import sys
- from StringIO import StringIO
s = StringIO(TEST_FILE_DATA)
env = TEST_ENVIRON.copy()
start_count = sys.getrefcount(s)
- from ZPublisher.HTTPRequest import HTTPRequest
+
req = HTTPRequest(s, env, None)
req.processInputs()
self.assertNotEqual(start_count, sys.getrefcount(s)) # Precondition
@@ -709,10 +695,9 @@
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')
@@ -721,11 +706,9 @@
def testFileIterator(self):
# checks fileupload object supports the iterator protocol
# collector entry 1837
- import sys
- from StringIO import StringIO
s = StringIO(TEST_FILE_DATA)
env = TEST_ENVIRON.copy()
- from ZPublisher.HTTPRequest import HTTPRequest
+
req = HTTPRequest(s, env, None)
req.processInputs()
f=req.form.get('file')
@@ -741,8 +724,6 @@
'SERVER_NAME': 'localhost',
'SERVER_PORT': '80',
}
- from StringIO import StringIO
- from ZPublisher.HTTPRequest import HTTPRequest
s = StringIO('')
# accessing request.debug from non-Zope3 code will raise an
@@ -780,8 +761,6 @@
'SERVER_NAME': 'localhost',
'SERVER_PORT': '80',
}
- from StringIO import StringIO
- from ZPublisher.HTTPRequest import HTTPRequest
s = StringIO('')
env = TEST_ENVIRON.copy()
@@ -801,8 +780,6 @@
'REMOTE_ADDR': '127.0.0.1',
'HTTP_X_FORWARDED_FOR': '10.1.20.30, 192.168.1.100',
}
- from StringIO import StringIO
- from ZPublisher.HTTPRequest import HTTPRequest, trusted_proxies
s = StringIO('')
env = TEST_ENVIRON.copy()
@@ -824,7 +801,6 @@
request = HTTPRequest(s, env, None)
self.assertEqual(request.getClientAddr(), '')
-
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(AuthCredentialsTests, 'test'))
More information about the Zope-Checkins
mailing list