'L{Agent.request} establishes a new connection to the host indicated by
the host part of the URI passed to it and issues a request using the
method, the path portion of the URI, the headers, and the body producer
passed to it.  It returns a L{Deferred} which fires with an
L{IResponse} from the server.'

def test_request(self):

    self.agent._getEndpoint = (lambda *args: self)
    headers = http_headers.Headers({'foo': ['bar']})
    body = object()
    self.agent.request('GET', 'http://example.com:1234/foo?bar', headers, body)
    protocol = self.protocol
    self.assertEqual(len(protocol.requests), 1)
    (req, res) = protocol.requests.pop()
    self.assertIsInstance(req, Request)
    self.assertEqual(req.method, 'GET')
    self.assertEqual(req.uri, '/foo?bar')
    self.assertEqual(req.headers, http_headers.Headers({'foo': ['bar'], 'host': ['example.com:1234']}))
    self.assertIdentical(req.bodyProducer, body)
