Fix test cases that fail when running behind a proxy

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.
This commit is contained in:
David Pursehouse
2013-07-23 10:51:15 +09:00
parent 66de6b528d
commit 9e771aa79c
2 changed files with 8 additions and 2 deletions
+1 -1
View 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>`.
+7 -1
View File
@@ -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)