def test_connectionFailed(self):
        """
        Check that L{ProxyClientFactory.clientConnectionFailed} produces
        a B{501} response to the parent request.
        """
        request = DummyRequest([b'foo'])
        factory = ProxyClientFactory(b'GET', b'/foo', b'HTTP/1.0',
                                     {b"accept": b"text/html"}, '', request)

        factory.clientConnectionFailed(None, None)
        self.assertEqual(request.responseCode, 501)
        self.assertEqual(request.responseMessage, b"Gateway error")
        self.assertEqual(
            list(request.responseHeaders.getAllRawHeaders()),
            [(b"Content-Type", [b"text/html"])])
        self.assertEqual(
            b''.join(request.written),
            b"<H1>Could not connect</H1>")
        self.assertEqual(request.finished, 1)

        Check that L{ProxyClientFactory.clientConnectionFailed} produces
        a B{501} response to the parent request.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_proxy.py