'When a connection is made by the Agent, it uses its pool\'s
C{getConnection} method to do so, with the endpoint returned by
C{self._getEndpoint}. The key used is C{(scheme, host, port)}.'

def test_connectUsesConnectionPool(self):

    endpoint = DummyEndpoint()
    class MyAgent(client.Agent, ):
        def _getEndpoint(this, uri):
            self.assertEqual((uri.scheme, uri.host, uri.port), ('http', 'foo', 80))
            return endpoint
    class DummyPool(object, ):
        connected = False
        persistent = False
        def getConnection(this, key, ep):
            this.connected = True
            self.assertEqual(ep, endpoint)
            self.assertEqual(key, ('http', 'foo', 80))
            return defer.succeed(StubHTTPProtocol())
    pool = DummyPool()
    agent = MyAgent(self.reactor, pool=pool)
    self.assertIdentical(pool, agent._pool)
    headers = http_headers.Headers()
    headers.addRawHeader('host', 'foo')
    bodyProducer = object()
    agent.request('GET', 'http://foo/', bodyProducer=bodyProducer, headers=headers)
    self.assertEqual(agent._pool.connected, True)
