660
660
self.assertEqual(l[2], (3, '34'))
661
661
self.assertEqual(l[3], (9, '9'))
662
662
# The server should have issued 4 requests
663
self.assertEqual(4, self.get_readonly_server().GET_request_nb)
663
self.assertEqual(4, server.GET_request_nb)
665
def test_readv_get_max_size(self):
666
server = self.get_readonly_server()
667
t = self._transport(server.get_url())
668
# force transport to issue multiple requests by limiting the number of
669
# bytes by request. Note that this apply to coalesced offsets only, a
670
# single range ill keep its size even if bigger than the limit.
672
l = list(t.readv('a', ((0, 1), (1, 1), (2, 4), (6, 4))))
673
self.assertEqual(l[0], (0, '0'))
674
self.assertEqual(l[1], (1, '1'))
675
self.assertEqual(l[2], (2, '2345'))
676
self.assertEqual(l[3], (6, '6789'))
677
# The server should have issued 3 requests
678
self.assertEqual(3, server.GET_request_nb)
666
681
class TestSingleRangeRequestServer(TestRangeRequestServer):
987
1002
def _file_tail(self, relpath, tail_amount):
988
1003
code, data = self.transport._get(relpath, [], tail_amount)
989
1004
self.assertTrue(code in (200, 206),'_get returns: %d' % code)
990
data.seek(-tail_amount + 1, 2)
1005
data.seek(-tail_amount, 2)
991
1006
return data.read(tail_amount)
993
1008
def test_range_header(self):
998
1013
self.assertEqual('789', self._file_tail('a', 3))
999
1014
# Syntactically invalid range
1000
self.assertListRaises(errors.InvalidRange,
1015
self.assertListRaises(errors.InvalidHttpRange,
1001
1016
self._file_contents, 'a', [(4, 3)])
1002
1017
# Semantically invalid range
1003
self.assertListRaises(errors.InvalidRange,
1018
self.assertListRaises(errors.InvalidHttpRange,
1004
1019
self._file_contents, 'a', [(42, 128)])