[Zope-Checkins] CVS: Zope2 - testRanges.py:1.1.2.3
Martijn Pieters
mj@digicool.com
Mon, 23 Apr 2001 11:05:14 -0400 (EDT)
Update of /cvs-repository/Zope2/lib/python/OFS/tests
In directory korak:/tmp/cvs-serv32586/OFS/tests
Modified Files:
Tag: mj-http_range_support-branch
testRanges.py
Log Message:
- Move tests for range support methods to ZPublisher tests package.
- Update tests to reflect added support for Etags.
- Fix typo in Etag refreshing call.
--- Updated File testRanges.py in package Zope2 --
--- testRanges.py 2001/04/18 23:57:46 1.1.2.2
+++ testRanges.py 2001/04/23 15:05:13 1.1.2.3
@@ -104,115 +104,9 @@
from Testing.makerequest import makerequest
from webdav.common import rfc1123_date
-from OFS.Image import parseRange, optimizeRanges
from mimetools import Message
from multifile import MultiFile
-class TestRangeHeaderParse(unittest.TestCase):
-
- # Utility methods
- def expectNone(self, header):
- result = parseRange(header)
- self.failUnless(result is None, 'Expected None, got %s' % `result`)
-
- def expectSets(self, header, sets):
- result = parseRange(header)
- self.failUnless(result == sets,
- 'Expected %s, got %s' % (`sets`, `result`))
-
- # Syntactically incorrect headers
- def testGarbage(self):
- self.expectNone('kjahskjhdfkgkjbnbb ehgdk dsahg wlkjew lew\n =lkdskue')
-
- def testIllegalSpec(self):
- self.expectNone('notbytes=0-1000')
-
- def testNoSets(self):
- self.expectNone('bytes=')
-
- def testEmptySets(self):
- self.expectNone('bytes=,,,')
-
- def testIllegalRange(self):
- self.expectNone('bytes=foo-bar')
-
- def testAlmostIntegers(self):
- self.expectNone('bytes=1.0-2.0')
-
- def testEndLowerThanStart(self):
- self.expectNone('bytes=5-4')
-
- # Correct headers
- def testSimpleRange(self):
- self.expectSets('bytes=2-20', [(2, 21)])
-
- def testSimpleRangeAndEmpty(self):
- self.expectSets('bytes=,2-20,', [(2, 21)])
-
- def testSuffixRange(self):
- self.expectSets('bytes=-100', [(-100, None)])
-
- def testOpenEnded(self):
- self.expectSets('bytes=100-', [(100, None)])
-
- def testStartEqualsEnd(self):
- self.expectSets('bytes=100-100', [(100, 101)])
-
- def testMultiple(self):
- self.expectSets('bytes=-100,,1-2,20-',
- [(-100, None), (1, 3), (20, None)])
-
- def testFirstByte(self):
- self.expectSets('bytes=0-0', [(0, 1)])
-
- def testNegativeZero(self):
- self.expectSets('bytes=-0', [(sys.maxint, None)])
-
-
-class TestOptimizeRanges(unittest.TestCase):
-
- def expectSets(self, sets, size, expect):
- result = optimizeRanges(sets, size)
- self.failUnless(result == expect,
- 'Expected %s, got %s' % (`expect`, `result`))
-
- def testExpandOpenEnd(self):
- self.expectSets([(1, 2), (5, None)], 50, [(1, 2), (5, 50)])
-
- def testMakeAbsolute(self):
- self.expectSets([(1, 2), (-5, None)], 50, [(1, 2), (45, 50)])
-
- def testNoOverlapInOrder(self):
- self.expectSets([(1, 5), (1000, 2000), (3000, None)], 5000,
- [(1, 5), (1000, 2000), (3000, 5000)])
-
- def testNoOverlapOutOfOrder(self):
- self.expectSets([(1000, 2000), (3000, None), (1, 5)], 5000,
- [(1, 5), (1000, 2000), (3000, 5000)])
-
- def testOverlapInOrder(self):
- self.expectSets([(1, 10), (8, 20), (25, None)], 5000,
- [(1, 20), (25, 5000)])
-
- def testOverlapOutOfOrder(self):
- self.expectSets([(25, 50), (8, None), (1, 10)], 5000,
- [(1, 5000)])
-
- def testAdjacentInOrder(self):
- self.expectSets([(1, 10), (10, 20), (25, 50)], 5000,
- [(1, 20), (25, 50)])
-
- def testAdjacentOutOfOrder(self):
- self.expectSets([(-5, None), (40, 45)], 50, [(40, 50)])
-
- def testOverLapAndOverflow(self):
- # Note that one endpoint lies beyond the end.
- self.expectSets([(-5, None), (40, 100)], 50, [(40, 50)])
-
- def testRemoveUnsatisfiable(self):
- self.expectSets([(sys.maxint, None), (10, 20)], 50, [(10, 20)])
-
-
def createBigFile():
# Create a file that is several 1<<16 blocks of data big, to force the
# use of chained Pdata objects.
@@ -493,25 +387,29 @@
# illegal if-modified since.
self.expectSingleRange('21-25,10-20', 10, 26, if_range='garbage')
- def testEqualIfRange(self):
+ def testEqualIfRangeDate(self):
self.expectSingleRange('21-25,10-20', 10, 26,
if_range=self.createLastModifiedDate())
- def testIsModifiedIfRange(self):
+ def testIsModifiedIfRangeDate(self):
self.expectOK('21-25,10-20',
if_range=self.createLastModifiedDate(offset=-100))
- def testIsNotModifiedIfRange(self):
- self.expectOK('21-25,10-20',
+ def testIsNotModifiedIfRangeDate(self):
+ self.expectSingleRange('21-25,10-20', 10, 26,
if_range=self.createLastModifiedDate(offset=100))
+ def testEqualIfRangeEtag(self):
+ self.expectSingleRange('21-25,10-20', 10, 26,
+ if_range=self.file.http__etag())
+
+ def testNotEqualIfRangeEtag(self):
+ self.expectOK('21-25,10-20',
+ if_range=self.file.http__etag() + 'bar')
+
def test_suite():
- suite = unittest.TestSuite()
- suite.addTest(unittest.makeSuite(TestRangeHeaderParse, 'test'))
- suite.addTest(unittest.makeSuite(TestOptimizeRanges, 'test'))
- suite.addTest(unittest.makeSuite(TestRequestRange, 'test'))
- return suite
+ return unittest.makeSuite(TestRequestRange, 'test')
def main():
unittest.TextTestRunner().run(test_suite())