From: David Pursehouse Date: Tue, 23 Jul 2013 01:51:15 +0000 (+0900) Subject: Fix test cases that fail when running behind a proxy X-Git-Tag: 2.0~11^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e771aa79cc3cdf2b625b31148247c05efdf4edd;p=services%2Fpython-requests.git 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. --- diff --git a/requests/adapters.py b/requests/adapters.py index 7b4916c..7e65c78 100644 --- a/requests/adapters.py +++ b/requests/adapters.py @@ -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 `. diff --git a/test_requests.py b/test_requests.py index f2b633b..274a8be 100755 --- a/test_requests.py +++ b/test_requests.py @@ -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)