[Zope-Checkins] CVS: Zope/lib/python/OFS/tests - testRanges.py:1.2.22.2 framework.py:NONE
Martijn Pieters
mj@zope.com
Tue, 4 Dec 2001 17:42:13 -0500
Update of /cvs-repository/Zope/lib/python/OFS/tests
In directory cvs.zope.org:/tmp/cvs-serv29434/lib/python/OFS/tests
Modified Files:
Tag: Zope-2_4-branch
testRanges.py
Removed Files:
Tag: Zope-2_4-branch
framework.py
Log Message:
Fix HTTP Range support; don't concatenate adjacent byte ranges, as this breaks
Acrobat PDF downloading.
=== Zope/lib/python/OFS/tests/testRanges.py 1.2.22.1 => 1.2.22.2 ===
#
##############################################################################
-
-import os, sys
-execfile(os.path.join(sys.path[0], 'framework.py'))
+import os, sys, unittest
import string, whrandom, cStringIO, time, re
-import Zope
+import ZODB
+from OFS.Application import Application
+from OFS.Folder import manage_addFolder
+from OFS.Image import manage_addFile
from Testing.makerequest import makerequest
from webdav.common import rfc1123_date
from mimetools import Message
from multifile import MultiFile
+def makeConnection():
+ import ZODB
+ from ZODB.DemoStorage import DemoStorage
+
+ s = DemoStorage(quota=(1<<20))
+ return ZODB.DB( s ).open()
+
def createBigFile():
# Create a file that is several 1<<16 blocks of data big, to force the
# use of chained Pdata objects.
@@ -114,28 +122,39 @@
# Test case setup and teardown
def setUp(self):
self.responseOut = cStringIO.StringIO()
- self.app = makerequest(Zope.app(), stdout=self.responseOut)
- try: self.app._delObject(TESTFOLDER_NAME)
- except AttributeError: pass
- self.app.manage_addFolder(TESTFOLDER_NAME)
-
- data = string.letters
- self.app[TESTFOLDER_NAME].manage_addFile('file', file=data,
- content_type='text/plain')
-
- self.file = self.app[TESTFOLDER_NAME].file
- self.data = data
-
- # Hack, we need a _p_mtime for the file, so we make sure that it has
- # one. We use a subtransaction, which means we can rollback later and
- # pretend we didn't touch the ZODB.
- get_transaction().commit()
+ self.connection = makeConnection()
+ try:
+ r = self.connection.root()
+ a = Application()
+ r['Application'] = a
+ self.root = a
+ self.app = makerequest(self.root, stdout=self.responseOut)
+ try: self.app._delObject(TESTFOLDER_NAME)
+ except AttributeError: pass
+ manage_addFolder(self.app, TESTFOLDER_NAME)
+ folder = getattr( self.app, TESTFOLDER_NAME )
+
+ data = string.letters
+ manage_addFile( folder, 'file'
+ , file=data, content_type='text/plain')
+
+ self.file = folder.file
+ self.data = data
+
+ # Hack, we need a _p_mtime for the file, so we make sure that it
+ # has one. We use a subtransaction, which means we can rollback
+ # later and pretend we didn't touch the ZODB.
+ get_transaction().commit()
+ except:
+ self.connection.close()
+ raise
def tearDown(self):
try: self.app._delObject(TESTFOLDER_NAME)
except AttributeError: pass
- get_transaction().commit()
- self.app._p_jar.close()
+ get_transaction().abort()
+ self.app._p_jar.sync()
+ self.connection.close()
self.app = None
del self.app
@@ -326,9 +345,6 @@
# A satisfiable and an unsatisfiable range
self.expectSingleRange('-0,3-23', 3, 24)
- def testAdjacentRanges(self):
- self.expectSingleRange('21-25,10-20', 10, 26)
-
def testEndOverflow(self):
l = len(self.data)
start, end = l - 10, l + 10
@@ -353,6 +369,9 @@
self.expectSingleRange(range, start, len(self.data))
# Multiple ranges
+ def testAdjacentRanges(self):
+ self.expectMultipleRanges('21-25,10-20', [(10, 21), (21, 26)])
+
def testMultipleRanges(self):
self.expectMultipleRanges('3-7,10-15', [(3, 8), (10, 16)])
@@ -372,10 +391,10 @@
def testIllegalIfRange(self):
# We assume that an illegal if-range is to be ignored, just like an
# illegal if-modified since.
- self.expectSingleRange('21-25,10-20', 10, 26, if_range='garbage')
+ self.expectSingleRange('21-25,10-21', 10, 26, if_range='garbage')
def testEqualIfRangeDate(self):
- self.expectSingleRange('21-25,10-20', 10, 26,
+ self.expectSingleRange('21-25,10-21', 10, 26,
if_range=self.createLastModifiedDate())
def testIsModifiedIfRangeDate(self):
@@ -383,15 +402,25 @@
if_range=self.createLastModifiedDate(offset=-100))
def testIsNotModifiedIfRangeDate(self):
- self.expectSingleRange('21-25,10-20', 10, 26,
+ self.expectSingleRange('21-25,10-21', 10, 26,
if_range=self.createLastModifiedDate(offset=100))
def testEqualIfRangeEtag(self):
- self.expectSingleRange('21-25,10-20', 10, 26,
+ self.expectSingleRange('21-25,10-21', 10, 26,
if_range=self.file.http__etag())
def testNotEqualIfRangeEtag(self):
self.expectOK('21-25,10-20',
if_range=self.file.http__etag() + 'bar')
-framework()
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest( unittest.makeSuite( TestRequestRange ) )
+ return suite
+
+def main():
+ unittest.TextTestRunner().run(test_suite())
+
+if __name__ == '__main__':
+ main()
=== Removed File Zope/lib/python/OFS/tests/framework.py ===