~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-12-13 16:29:49 UTC
  • mto: (2183.1.1 Aaron's integration)
  • mto: This revision was merged to the branch mainline in revision 2184.
  • Revision ID: v.ladeuil+lp@free.fr-20061213162949-xd0gmdi5uj73l8ya
Thanks again to Aaron, the http server RFC2616 compliance
continue to progress.

* bzrlib/tests/test_http.py:
(TestRanges, TestRanges_urllib, TestRanges_pycurl): New tests
classes for the Range header.

* bzrlib/tests/HttpServer.py:
(TestingHTTPRequestHandler.parse_ranges): RFC2616 says that
'start > end' is a syntax error for a range specifier.
(TestingHTTPRequestHandler.do_GET.check_range): Update
self._satisfiable_ranges, satisfiable_ranges is a free variable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
621
621
    """Tests range requests refusing server for pycurl implementation"""
622
622
 
623
623
 
 
624
class TestRanges(object):
 
625
    """Test the Range header in GET methods..
 
626
 
 
627
    This MUST be used by daughter classes that also inherit from
 
628
    TestCaseWithWebserver.
 
629
 
 
630
    We can't inherit directly from TestCaseWithWebserver or the
 
631
    test framework will try to create an instance which cannot
 
632
    run, its implementation being incomplete.
 
633
    """
 
634
 
 
635
    def setUp(self):
 
636
        TestCaseWithWebserver.setUp(self)
 
637
        self.build_tree_contents([('a', '0123456789')],)
 
638
        server = self.get_readonly_server()
 
639
        self.transport = self._transport(server.get_url())
 
640
 
 
641
    def _file_contents(self, relpath, ranges, tail_amount=0):
 
642
         code, data = self.transport._get(relpath, ranges)
 
643
         self.assertTrue(code in (200, 206),'_get returns: %d' % code)
 
644
         for start, end in ranges:
 
645
             data.seek(start)
 
646
             yield data.read(end - start + 1)
 
647
 
 
648
    def _file_tail(self, relpath, tail_amount):
 
649
         code, data = self.transport._get(relpath, [], tail_amount)
 
650
         self.assertTrue(code in (200, 206),'_get returns: %d' % code)
 
651
         data.seek(-tail_amount + 1, 2)
 
652
         return data.read(tail_amount)
 
653
 
 
654
    def test_range_header(self):
 
655
        # Valid ranges
 
656
        map(self.assertEqual,['0', '234'],
 
657
            list(self._file_contents('a', [(0,0), (2,4)])),)
 
658
        # Tail
 
659
        self.assertEqual('789', self._file_tail('a', 3))
 
660
        # Syntactically invalid range
 
661
        self.assertRaises(errors.InvalidRange,
 
662
                          self.transport._get, 'a', [(4, 3)])
 
663
        # Semantically invalid range
 
664
        self.assertRaises(errors.InvalidRange,
 
665
                          self.transport._get, 'a', [(42, 128)])
 
666
 
 
667
 
 
668
class TestRanges_urllib(TestRanges, TestCaseWithWebserver):
 
669
    """Test the Range header in GET methods for urllib implementation"""
 
670
 
 
671
    _transport = HttpTransport_urllib
 
672
 
 
673
 
 
674
class TestRanges_pycurl(TestWithTransport_pycurl,
 
675
                        TestRanges,
 
676
                        TestCaseWithWebserver):
 
677
    """Test the Range header in GET methods for pycurl implementation"""