From: Wilfred Hughes Date: Wed, 27 Feb 2013 16:01:36 +0000 (+0000) Subject: [kennethreitz/requests#1208] adding unit test for max_retries X-Git-Tag: v1.2.0~29^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=18b29ea00563a0bf8e15666806117444c87ac23f;p=services%2Fpython-requests.git [kennethreitz/requests#1208] adding unit test for max_retries --- diff --git a/test_requests.py b/test_requests.py index e12722d..51719e6 100644 --- a/test_requests.py +++ b/test_requests.py @@ -354,5 +354,26 @@ class RequestsTestCase(unittest.TestCase): r = requests.Request(url=HTTPBIN) self.assertRaises(ValueError, requests.Session().send, r) + def test_can_specify_retries(self): + # monkey patch urlopen + from requests.packages.urllib3.poolmanager import HTTPConnectionPool + old_urlopen = HTTPConnectionPool.urlopen + + max_retries_used = [] + def urlopen(*args, **kwargs): + """Save what value we used for retries each time we call urlopen.""" + max_retries_used.append(kwargs.get('retries')) + return old_urlopen(*args, **kwargs) + + HTTPConnectionPool.urlopen = urlopen + + # do the request and check that max_retries was passed through + requests.get(httpbin('get'), max_retries=5) + self.assertEqual(max_retries_used, [5]) + + # undo monkey patch + HTTPConnectionPool.urlopen = old_urlopen + + if __name__ == '__main__': unittest.main()