/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: Canonical.com Patch Queue Manager
  • Date: 2006-12-13 19:15:34 UTC
  • mfrom: (2183.1.1 Aaron's integration)
  • Revision ID: pqm@pqm.ubuntu.com-20061213191534-c948e178bdeb5d36
Make test HTTP server's range handling more spec-compliant (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
745
745
 
746
746
    def test_HTTP_PROXY_with_NO_PROXY(self):
747
747
        raise TestSkipped()
 
748
 
 
749
 
 
750
class TestRanges(object):
 
751
    """Test the Range header in GET methods..
 
752
 
 
753
    This MUST be used by daughter classes that also inherit from
 
754
    TestCaseWithWebserver.
 
755
 
 
756
    We can't inherit directly from TestCaseWithWebserver or the
 
757
    test framework will try to create an instance which cannot
 
758
    run, its implementation being incomplete.
 
759
    """
 
760
 
 
761
    def setUp(self):
 
762
        TestCaseWithWebserver.setUp(self)
 
763
        self.build_tree_contents([('a', '0123456789')],)
 
764
        server = self.get_readonly_server()
 
765
        self.transport = self._transport(server.get_url())
 
766
 
 
767
    def _file_contents(self, relpath, ranges, tail_amount=0):
 
768
         code, data = self.transport._get(relpath, ranges)
 
769
         self.assertTrue(code in (200, 206),'_get returns: %d' % code)
 
770
         for start, end in ranges:
 
771
             data.seek(start)
 
772
             yield data.read(end - start + 1)
 
773
 
 
774
    def _file_tail(self, relpath, tail_amount):
 
775
         code, data = self.transport._get(relpath, [], tail_amount)
 
776
         self.assertTrue(code in (200, 206),'_get returns: %d' % code)
 
777
         data.seek(-tail_amount + 1, 2)
 
778
         return data.read(tail_amount)
 
779
 
 
780
    def test_range_header(self):
 
781
        # Valid ranges
 
782
        map(self.assertEqual,['0', '234'],
 
783
            list(self._file_contents('a', [(0,0), (2,4)])),)
 
784
        # Tail
 
785
        self.assertEqual('789', self._file_tail('a', 3))
 
786
        # Syntactically invalid range
 
787
        self.assertRaises(errors.InvalidRange,
 
788
                          self.transport._get, 'a', [(4, 3)])
 
789
        # Semantically invalid range
 
790
        self.assertRaises(errors.InvalidRange,
 
791
                          self.transport._get, 'a', [(42, 128)])
 
792
 
 
793
 
 
794
class TestRanges_urllib(TestRanges, TestCaseWithWebserver):
 
795
    """Test the Range header in GET methods for urllib implementation"""
 
796
 
 
797
    _transport = HttpTransport_urllib
 
798
 
 
799
 
 
800
class TestRanges_pycurl(TestWithTransport_pycurl,
 
801
                        TestRanges,
 
802
                        TestCaseWithWebserver):
 
803
    """Test the Range header in GET methods for pycurl implementation"""