Ticket #6115: 6115.patch

File 6115.patch, 2.3 KB (added by moijes12, 5 years ago)
  • twisted/web/test/test_http.py

     
    2121from twisted.web import http, http_headers
    2222from twisted.web.http import PotentialDataLoss, _DataLoss
    2323from twisted.web.http import _IdentityTransferDecoder
     24from twisted.web.http import parseContentRange
    2425from twisted.internet.task import Clock
    2526from twisted.internet.error import ConnectionLost
    2627from twisted.protocols import loopback
    2728from twisted.test.proto_helpers import StringTransport
    2829from twisted.test.test_internet import DummyProducer
    2930from twisted.web.test.requesthelper import DummyChannel
     31from twisted.web.test.test_web import DummyRequest
    3032
    3133
    3234
    33 
    3435class DateTimeTest(unittest.TestCase):
    3536    """Test date parsing functions."""
    3637
     
    18771878              b"Version: HTTP/1.1",
    18781879              b"Request: /foo",
    18791880              b"'''\n4\ndefg'''\n")])
     1881
     1882
     1883
     1884class ParseContentRangeTests(unittest.TestCase):
     1885    """
     1886    Tests parsing of the content-range header.
     1887    """
     1888   
     1889    def test_raiseValueErrorForNonByteData(self):
     1890        """
     1891        L{parseContentrange} raises ValueError for non-byte type data in
     1892        content-range header.
     1893        """
     1894        request = DummyRequest([])
     1895        request.headers['range'] = 'foo'
     1896        self.assertRaises(ValueError, parseContentRange, request.headers['range'])
     1897
     1898
     1899    def test_realLengthNone(self):
     1900        """
     1901        L{parseContentRange} returns realLength as None if * is passed as
     1902        realLength.
     1903        """
     1904        request = DummyRequest([])
     1905        request.headers['range'] = 'bytes 1-3/*'
     1906        start, end, realLength = parseContentRange(request.headers['range'])
     1907        self.assertEquals(realLength, None)
     1908
     1909
     1910    def test_returnedContentLength(self):
     1911        """
     1912        L{parseContentRange} returns start, end and real content length
     1913        correctly as passed in content-range header.
     1914        """
     1915        request = DummyRequest([])
     1916        request.headers['range'] = 'bytes 1-3/10'
     1917        start, end, realLength = parseContentRange(request.headers['range'])
     1918        self.assertEqual(start, 1)
     1919        self.assertEqual(end, 3)
     1920        self.assertEqual(realLength, 10)