Ticket #6391: 6391_improved.patch

File 6391_improved.patch, 2.4 KB (added by eddie, 7 years ago)

added unit test

  • twisted/web/http.py

     
    791791
    792792
    793793    def __repr__(self):
    794         return '<%s %s %s>'% (self.method, self.uri, self.clientproto)
     794                """
     795                Return the class name, address, method, uri and client protocol of the
     796                C{Request} instance as a C{string} in the form
     797                        <CLASSNAME at ADDRESS method=METHOD uri=URI clientproto=CLIENTPROTOCOL>
     798               
     799                @return: C{string} in the form
     800                        <CLASSNAME at ADDRESS method=METHOD uri=URI clientproto=CLIENTPROTOCOL>
     801                @rtype: C{string}
     802                """
     803                return '<%s.%s at 0x%x method=%s uri=%s clientproto=%s>' % (
     804                        nativeString(self.__module__),
     805                        nativeString(self.__class__.__name__),
     806                        id(self),
     807                        nativeString(self.method),
     808                        nativeString(self.uri),
     809                        nativeString(self.clientproto))
    795810
    796811    def process(self):
    797812        """
     
    847862
    848863        @rtype: C{bytes} or C{NoneType}
    849864        @return: The value of the specified header, or C{None} if that header
    850             was not present in the request.
     865                was not present in the request.
    851866        """
    852867        value = self.requestHeaders.getRawHeaders(key)
    853868        if value is not None:
  • twisted/web/test/test_http.py

     
    16531653        self.assertRaises(RuntimeError, req.finish)
    16541654
    16551655
     1656        def test_repr(self):
     1657                """
     1658                L{Request.__repr__} returns the class name, address, uri and client protocol of
     1659                the C{Request} instance as a C{string} in the form
     1660                        <ClASSNAME at ADDRESS method=METHOD uri=URI clientproto=CLIENTPROTOCOL>
     1661                """
     1662                request = http.Request(DummyChannel(), False)
     1663                self.assertEqual(repr(request),
     1664                        '<twisted.web.http.Request at 0x%x method=(no method yet) uri=(no uri yet) clientproto=(no clientproto yet)>' % (
     1665                        id(request),))
     1666                request.clientproto = b'HTTP/1.0'
     1667                request.method = b'GET'
     1668                request.uri = b'/foo/bar'
     1669                self.assertEqual(repr(request),
     1670                        '<twisted.web.http.Request at 0x%x method=GET uri=/foo/bar/ clientproto=HTTP/1.0>' % (
     1671                        id(request),))
    16561672
     1673
    16571674class MultilineHeadersTestCase(unittest.TestCase):
    16581675    """
    16591676    Tests to exercise handling of multiline headers by L{HTTPClient}.  RFCs 1945