Fix test cases that fail when running behind a proxy
authorDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 23 Jul 2013 01:51:15 +0000 (10:51 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Tue, 23 Jul 2013 07:55:27 +0000 (16:55 +0900)
When sending a request via `Session.send()` the proxies must be
explicitly given with the `proxies` argument.  This is not done
in the test cases, which means that they fail when run on a system
that is behind a proxy.

Update test cases to make sure the proxies are set in the sessions.

requests/adapters.py
test_requests.py

index 7b4916c..7e65c78 100644 (file)
@@ -214,7 +214,7 @@ class HTTPAdapter(BaseAdapter):
         If the message is being sent through a proxy, the full URL has to be
         used. Otherwise, we should only use the path portion of the URL.
 
-        This shoudl not be called from user code, and is only exposed for use
+        This should not be called from user code, and is only exposed for use
         when subclassing the
         :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
 
index f2b633b..274a8be 100755 (executable)
@@ -12,7 +12,7 @@ import pickle
 import requests
 from requests.auth import HTTPDigestAuth
 from requests.adapters import HTTPAdapter
-from requests.compat import str, cookielib
+from requests.compat import str, cookielib, getproxies
 from requests.cookies import cookiejar_from_dict
 from requests.exceptions import InvalidURL, MissingSchema
 from requests.structures import CaseInsensitiveDict
@@ -88,11 +88,14 @@ class RequestsTestCase(unittest.TestCase):
             "http://example.com/path?key=value&a=b#fragment")
 
     def test_mixed_case_scheme_acceptable(self):
+        proxies = getproxies()
         s = requests.Session()
+        s.proxies = proxies
         r = requests.Request('GET', 'http://httpbin.org/get')
         r = s.send(r.prepare())
         self.assertEqual(r.status_code,200)
         s = requests.Session()
+        s.proxies = proxies
         r = requests.Request('GET', 'HTTP://httpbin.org/get')
         r = s.send(r.prepare())
         self.assertEqual(r.status_code,200)
@@ -118,6 +121,7 @@ class RequestsTestCase(unittest.TestCase):
     def test_HTTP_200_OK_GET_ALTERNATIVE(self):
         r = requests.Request('GET', httpbin('get'))
         s = requests.Session()
+        s.proxies = getproxies()
 
         r = s.send(r.prepare())
 
@@ -447,6 +451,7 @@ class RequestsTestCase(unittest.TestCase):
         prep = req.prepare()
 
         s = requests.Session()
+        s.proxies = getproxies()
         resp = s.send(prep)
 
         self.assertTrue(hasattr(resp, 'hook_working'))
@@ -536,6 +541,7 @@ class RequestsTestCase(unittest.TestCase):
         s = requests.Session()
 
         s = pickle.loads(pickle.dumps(s))
+        s.proxies = getproxies()
 
         r = s.send(r.prepare())
         self.assertEqual(r.status_code, 200)