Skip to content
Myr

Fix test cases that fail when running behind a proxy

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by David Pursehouse · committed by David Pursehouse · parent 66de6b5 · Browse files · 2 files+8 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+8 added−2 removed

  • other:+8 added−2 removed

2 files+8 added−2 removed

modified:requests/adapters.py+1 added-1 removed
212 unmodified lines
213214 If the message is being sent through a proxy, the full URL has to be215 used. Otherwise, we should only use the path portion of the URL.216217 This shoudl not be called from user code, and is only exposed for use217 This should not be called from user code, and is only exposed for use218 when subclassing the219 :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.220221 :param request: The :class:`PreparedRequest <PreparedRequest>` being sent.
121 unmodified lines
modified:test_requests.py+7 added-1 removed
10 unmodified lines
1112import requests13from requests.auth import HTTPDigestAuth14from requests.adapters import HTTPAdapter15from requests.compat import str, cookielib15from requests.compat import str, cookielib, getproxies16from requests.cookies import cookiejar_from_dict17from requests.exceptions import InvalidURL, MissingSchema18from requests.structures import CaseInsensitiveDict19
67 unmodified lines
87 self.assertEqual(request.url,88 "http://example.com/path?key=value&a=b#fragment")8990 def test_mixed_case_scheme_acceptable(self):91 proxies = getproxies()92 s = requests.Session()93 s.proxies = proxies94 r = requests.Request('GET', 'http://httpbin.org/get')95 r = s.send(r.prepare())96 self.assertEqual(r.status_code,200)97 s = requests.Session()98 s.proxies = proxies99 r = requests.Request('GET', 'HTTP://httpbin.org/get')100 r = s.send(r.prepare())101 self.assertEqual(r.status_code,200)102 r = requests.Request('GET', 'hTTp://httpbin.org/get')
17 unmodified lines
120121 def test_HTTP_200_OK_GET_ALTERNATIVE(self):122 r = requests.Request('GET', httpbin('get'))123 s = requests.Session()124 s.proxies = getproxies()125126 r = s.send(r.prepare())127128 self.assertEqual(r.status_code, 200)
321 unmodified lines
450 req = requests.Request('GET', HTTPBIN, hooks={'response': hook})451 prep = req.prepare()452453 s = requests.Session()454 s.proxies = getproxies()455 resp = s.send(prep)456457 self.assertTrue(hasattr(resp, 'hook_working'))458
81 unmodified lines
540 r = requests.Request('GET', httpbin('get'))541 s = requests.Session()542543 s = pickle.loads(pickle.dumps(s))544 s.proxies = getproxies()545546 r = s.send(r.prepare())547 self.assertEqual(r.status_code, 200)548
239 unmodified lines