/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_http.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-17 13:58:01 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-20061017135801-3fb63746e0ea8fcf
Fix #62276 and #62029 by providing a more robust http range handling.

* bzrlib/transport/http/_urllib.py:
(HttpTransport_urllib.__init__): Forget about _accept_ranges, the
base class handles that.
(HttpTransport_urllib._get): Takes _range_hint into account.

* bzrlib/transport/http/_pycurl.py:
(PyCurlTransport): Doc fix. Hey ! Urllib had shrunk the gap here !
(PyCurlTransport._get_ranged): Takes _range_hint into account.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase.__init__): Add _range_hint attribute. Give it
to the clones too.
(HttpTransportBase.readv): If we don't get the data we need, try
simpler requests.
(HttpTransportBase.attempted_range_header): Build the range header
taking into account what we had learned from the server
capabilites in previous requests.
(HttpTransportBase.range_header): Small doc fix.

* bzrlib/tests/test_http.py:
(TestPost._test_post_body_is_received): Oops, miss that one during
the merge. UnsupportedProtocol should be prefixed by 'errors.'.
(TestRangeRequestServer.setUp): Use build_tree_contents, not
build_tree or we don't end up with the content we need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
302
302
        url = '%s://%s:%s/' % (scheme, server.host, server.port)
303
303
        try:
304
304
            http_transport = get_transport(url)
305
 
        except UnsupportedProtocol:
 
305
        except errors.UnsupportedProtocol:
306
306
            raise TestSkipped('%s not available' % scheme)
307
307
        code, response = http_transport._post('abc def end-of-body')
308
308
        self.assertTrue(
530
530
 
531
531
    def setUp(self):
532
532
        TestCaseWithWebserver.setUp(self)
533
 
        self.build_tree(['0123456789',],
534
 
                        line_endings='binary',
535
 
                        transport=self.get_transport())
 
533
        self.build_tree_contents([('a', '0123456789')],)
536
534
 
537
535
    """Tests readv requests against server"""
538
536
 
539
537
    def test_readv(self):
540
538
        server = self.get_readonly_server()
541
539
        t = self._transport(server.get_url())
542
 
        l = list(t.readv('0123456789', ((0, 1), (1, 1), (3, 2), (9, 1))))
 
540
        l = list(t.readv('a', ((0, 1), (1, 1), (3, 2), (9, 1))))
543
541
        self.assertEqual(l[0], (0, '0'))
544
542
        self.assertEqual(l[1], (1, '1'))
545
543
        self.assertEqual(l[2], (3, '34'))
548
546
    def test_readv_out_of_order(self):
549
547
        server = self.get_readonly_server()
550
548
        t = self._transport(server.get_url())
551
 
        l = list(t.readv('0123456789', ((1, 1), (9, 1), (0, 1), (3, 2))))
 
549
        l = list(t.readv('a', ((1, 1), (9, 1), (0, 1), (3, 2))))
552
550
        self.assertEqual(l[0], (1, '1'))
553
551
        self.assertEqual(l[1], (9, '9'))
554
552
        self.assertEqual(l[2], (0, '0'))
561
559
        # This is intentionally reading off the end of the file
562
560
        # since we are sure that it cannot get there
563
561
        self.assertListRaises((errors.ShortReadvError, AssertionError),
564
 
                              t.readv, '0123456789', [(1,1), (8,10)])
 
562
                              t.readv, 'a', [(1,1), (8,10)])
565
563
 
566
564
        # This is trying to seek past the end of the file, it should
567
565
        # also raise a special error
568
566
        self.assertListRaises(errors.ShortReadvError,
569
 
                              t.readv, '0123456789', [(12,2)])
 
567
                              t.readv, 'a', [(12,2)])
570
568
 
571
569
 
572
570
class TestSingleRangeRequestServer(TestRangeRequestServer):
609
607
    """Tests range requests refusing server for pycurl implementation"""
610
608
 
611
609
 
612