add a test for max_redirects in safe/normal modes
authorShivaram Lingamneni <slingamn@cs.stanford.edu>
Thu, 3 May 2012 08:21:37 +0000 (01:21 -0700)
committerShivaram Lingamneni <slingamn@cs.stanford.edu>
Thu, 3 May 2012 08:29:12 +0000 (01:29 -0700)
tests/test_requests.py

index fb0d75c05668ca7482d012257c9fc239bdd82538..db176f512c0420fc42d1685586786d615568f3ad 100755 (executable)
@@ -847,5 +847,15 @@ class RequestsTestSuite(TestSetup, TestBaseMixin, unittest.TestCase):
         r = requests.get(httpbin('status', '404'))
         r.text
 
+    def test_max_redirects(self):
+        def unsafe_callable():
+            requests.get("http://httpbin.org/redirect/3", config=dict(max_redirects=2))
+        self.assertRaises(requests.exceptions.TooManyRedirects, unsafe_callable)
+
+        # add safe mode
+        response = requests.get("http://httpbin.org/redirect/3", config=dict(safe_mode=True, max_redirects=2))
+        self.assertTrue(response.content is None)
+        self.assertTrue(isinstance(response.error, requests.exceptions.TooManyRedirects))
+
 if __name__ == '__main__':
     unittest.main()