~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-13 15:53:16 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061013155316-163e2bef7fa42490
New tests for http range requests handling.

* bzrlib/tests/test_http.py:
(TestRangeRequestServer): New class implementing tests involving
range requests.
(TestSingleRangeRequestServer,
TestSingleRangeRequestServer_urllib,
TestSingleRangeRequestServer_pycurl, TestNoRangeRequestServer,
TestNoRangeRequestServer_urllib,
TestNoRangeRequestServer_pycurl):New classes testing http
transports behavior against bogus range request handling servers.

* bzrlib/tests/__init__.py:
(TestCase.assertListRaises): Gratefully accepted from
bzrlib/tests/test_transport_implementations.py

* bzrlib/tests/test_transport_implementations.py:
(TransportTests.test_has.assertListRaises): Generously given to
bzrlib/tests/__init__.py.

* bzrlib/tests/HTTPTestUtil.py:
(SingleRangeRequestHandler): New class implementing a server that
handle only range requests by bogusly returning only the first
requested range.
(NoRangeRequestHandler): New class implementing a server that
silently ignores range requests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
    BadStatusRequestHandler,
40
40
    ForbiddenRequestHandler,
41
41
    InvalidStatusRequestHandler,
 
42
    NoRangeRequestHandler,
 
43
    SingleRangeRequestHandler,
42
44
    TestCaseWithWebserver,
43
45
    WallRequestHandler,
44
46
    )
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)
 
518
 
 
519
 
 
520
class TestRangeRequestServer(object):
 
521
    """Test the http connections.
 
522
 
 
523
    This MUST be used by daughter classes that also inherit from
 
524
    TestCaseWithWebserver.
 
525
 
 
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.
 
529
    """
 
530
 
 
531
    def setUp(self):
 
532
        TestCaseWithWebserver.setUp(self)
 
533
        self.build_tree(['0123456789',],
 
534
                        line_endings='binary',
 
535
                        transport=self.get_transport())
 
536
 
 
537
    """Tests readv requests against server"""
 
538
 
 
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'))
 
547
 
 
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'))
 
556
 
 
557
    def test_readv_short_read(self):
 
558
        server = self.get_readonly_server()
 
559
        t = self._transport(server.get_url())
 
560
 
 
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)])
 
565
 
 
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)])
 
570
 
 
571
 
 
572
class TestSingleRangeRequestServer(TestRangeRequestServer):
 
573
    """Test readv against a server which accept only single range requests"""
 
574
 
 
575
    def create_transport_readonly_server(self):
 
576
        return HttpServer(SingleRangeRequestHandler)
 
577
 
 
578
 
 
579
class TestSingleRangeRequestServer_urllib(TestSingleRangeRequestServer,
 
580
                                          TestCaseWithWebserver):
 
581
    """Tests single range requests accepting server for urllib implementation"""
 
582
 
 
583
    _transport = HttpTransport_urllib
 
584
 
 
585
 
 
586
class TestSingleRangeRequestServer_pycurl(TestWithTransport_pycurl,
 
587
                                          TestSingleRangeRequestServer,
 
588
                                          TestCaseWithWebserver):
 
589
    """Tests single range requests accepting server for pycurl implementation"""
 
590
 
 
591
 
 
592
class TestNoRangeRequestServer(TestRangeRequestServer):
 
593
    """Test readv against a server which do not accept range requests"""
 
594
 
 
595
    def create_transport_readonly_server(self):
 
596
        return HttpServer(NoRangeRequestHandler)
 
597
 
 
598
 
 
599
class TestNoRangeRequestServer_urllib(TestNoRangeRequestServer,
 
600
                                      TestCaseWithWebserver):
 
601
    """Tests range requests refusing server for urllib implementation"""
 
602
 
 
603
    _transport = HttpTransport_urllib
 
604
 
 
605
 
 
606
class TestNoRangeRequestServer_pycurl(TestWithTransport_pycurl,
 
607
                               TestNoRangeRequestServer,
 
608
                               TestCaseWithWebserver):
 
609
    """Tests range requests refusing server for pycurl implementation"""
 
610
 
 
611
 
 
612