'Check that L{ProxyClientFactory.clientConnectionFailed} produces
a B{501} response to the parent request.'

def test_connectionFailed(self):

    request = DummyRequest(['foo'])
    factory = ProxyClientFactory('GET', '/foo', 'HTTP/1.0', {'accept': 'text/html'}, '', request)
    factory.clientConnectionFailed(None, None)
    self.assertEqual(request.responseCode, 501)
    self.assertEqual(request.responseMessage, 'Gateway    error')
    self.assertEqual(list(request.responseHeaders.getAllRawHeaders()), [('Content-Type', ['text/html'])])
    self.assertEqual(''.join(request.written), '<H1>Could    not    connect</H1>')
    self.assertEqual(request.finished, 1)
