621
621
"""Tests range requests refusing server for pycurl implementation"""
624
class TestRanges(object):
625
"""Test the Range header in GET methods..
627
This MUST be used by daughter classes that also inherit from
628
TestCaseWithWebserver.
630
We can't inherit directly from TestCaseWithWebserver or the
631
test framework will try to create an instance which cannot
632
run, its implementation being incomplete.
636
TestCaseWithWebserver.setUp(self)
637
self.build_tree_contents([('a', '0123456789')],)
638
server = self.get_readonly_server()
639
self.transport = self._transport(server.get_url())
641
def _file_contents(self, relpath, ranges, tail_amount=0):
642
code, data = self.transport._get(relpath, ranges)
643
self.assertTrue(code in (200, 206),'_get returns: %d' % code)
644
for start, end in ranges:
646
yield data.read(end - start + 1)
648
def _file_tail(self, relpath, tail_amount):
649
code, data = self.transport._get(relpath, [], tail_amount)
650
self.assertTrue(code in (200, 206),'_get returns: %d' % code)
651
data.seek(-tail_amount + 1, 2)
652
return data.read(tail_amount)
654
def test_range_header(self):
656
map(self.assertEqual,['0', '234'],
657
list(self._file_contents('a', [(0,0), (2,4)])),)
659
self.assertEqual('789', self._file_tail('a', 3))
660
# Syntactically invalid range
661
self.assertRaises(errors.InvalidRange,
662
self.transport._get, 'a', [(4, 3)])
663
# Semantically invalid range
664
self.assertRaises(errors.InvalidRange,
665
self.transport._get, 'a', [(42, 128)])
668
class TestRanges_urllib(TestRanges, TestCaseWithWebserver):
669
"""Test the Range header in GET methods for urllib implementation"""
671
_transport = HttpTransport_urllib
674
class TestRanges_pycurl(TestWithTransport_pycurl,
676
TestCaseWithWebserver):
677
"""Test the Range header in GET methods for pycurl implementation"""