'If the limit of redirects specified to L{client.RedirectAgent} is
reached, the deferred fires with L{ResponseFailed} error wrapping
a L{InfiniteRedirection} exception.'

def test_redirectLimit(self):

    agent = self.buildAgentForWrapperTest(self.reactor)
    redirectAgent = client.RedirectAgent(agent, 1)
    deferred = redirectAgent.request('GET', 'http://example.com/foo')
    (req, res) = self.protocol.requests.pop()
    headers = http_headers.Headers({'location': ['http://example.com/bar']})
    response = Response(('HTTP', 1, 1), 302, 'OK', headers, None)
    res.callback(response)
    (req2, res2) = self.protocol.requests.pop()
    response2 = Response(('HTTP', 1, 1), 302, 'OK', headers, None)
    res2.callback(response2)
    fail = self.failureResultOf(deferred, client.ResponseFailed)
    fail.value.reasons[0].trap(error.InfiniteRedirection)
    self.assertEqual('http://example.com/foo', fail.value.reasons[0].value.location)
    self.assertEqual(302, fail.value.response.code)
