513
515
self.assertEqual('HTTP/1.1 200 OK\r\n',
514
516
sock.recv(4096, socket.MSG_WAITALL))
515
517
self.assertEqual('abc', server.received_bytes)
520
class TestRangeRequestServer(object):
521
"""Test the http connections.
523
This MUST be used by daughter classes that also inherit from
524
TestCaseWithWebserver.
526
We can't inherit directly from TestCaseWithWebserver or the
527
test framework will try to create an instance which cannot
528
run, its implementation being incomplete.
532
TestCaseWithWebserver.setUp(self)
533
self.build_tree(['0123456789',],
534
line_endings='binary',
535
transport=self.get_transport())
537
"""Tests readv requests against server"""
539
def test_readv(self):
540
server = self.get_readonly_server()
541
t = self._transport(server.get_url())
542
l = list(t.readv('0123456789', ((0, 1), (1, 1), (3, 2), (9, 1))))
543
self.assertEqual(l[0], (0, '0'))
544
self.assertEqual(l[1], (1, '1'))
545
self.assertEqual(l[2], (3, '34'))
546
self.assertEqual(l[3], (9, '9'))
548
def test_readv_out_of_order(self):
549
server = self.get_readonly_server()
550
t = self._transport(server.get_url())
551
l = list(t.readv('0123456789', ((1, 1), (9, 1), (0, 1), (3, 2))))
552
self.assertEqual(l[0], (1, '1'))
553
self.assertEqual(l[1], (9, '9'))
554
self.assertEqual(l[2], (0, '0'))
555
self.assertEqual(l[3], (3, '34'))
557
def test_readv_short_read(self):
558
server = self.get_readonly_server()
559
t = self._transport(server.get_url())
561
# This is intentionally reading off the end of the file
562
# since we are sure that it cannot get there
563
self.assertListRaises((errors.ShortReadvError, AssertionError),
564
t.readv, '0123456789', [(1,1), (8,10)])
566
# This is trying to seek past the end of the file, it should
567
# also raise a special error
568
self.assertListRaises(errors.ShortReadvError,
569
t.readv, '0123456789', [(12,2)])
572
class TestSingleRangeRequestServer(TestRangeRequestServer):
573
"""Test readv against a server which accept only single range requests"""
575
def create_transport_readonly_server(self):
576
return HttpServer(SingleRangeRequestHandler)
579
class TestSingleRangeRequestServer_urllib(TestSingleRangeRequestServer,
580
TestCaseWithWebserver):
581
"""Tests single range requests accepting server for urllib implementation"""
583
_transport = HttpTransport_urllib
586
class TestSingleRangeRequestServer_pycurl(TestWithTransport_pycurl,
587
TestSingleRangeRequestServer,
588
TestCaseWithWebserver):
589
"""Tests single range requests accepting server for pycurl implementation"""
592
class TestNoRangeRequestServer(TestRangeRequestServer):
593
"""Test readv against a server which do not accept range requests"""
595
def create_transport_readonly_server(self):
596
return HttpServer(NoRangeRequestHandler)
599
class TestNoRangeRequestServer_urllib(TestNoRangeRequestServer,
600
TestCaseWithWebserver):
601
"""Tests range requests refusing server for urllib implementation"""
603
_transport = HttpTransport_urllib
606
class TestNoRangeRequestServer_pycurl(TestWithTransport_pycurl,
607
TestNoRangeRequestServer,
608
TestCaseWithWebserver):
609
"""Tests range requests refusing server for pycurl implementation"""