|
40 | 40 | # listening on that port)
|
41 | 41 | TARPIT = 'http://10.255.255.1'
|
42 | 42 |
|
| 43 | +# This is to avoid waiting the timeout of using TARPIT |
| 44 | +INVALID_PROXY='http://localhost:1' |
| 45 | + |
43 | 46 | try:
|
44 | 47 | from ssl import SSLContext
|
45 | 48 | del SSLContext
|
@@ -551,6 +554,42 @@ def test_proxy_error_on_bad_url(self, httpbin, httpbin_secure):
|
551 | 554 | with pytest.raises(InvalidProxyURL):
|
552 | 555 | requests.get(httpbin(), proxies={'http': 'http:///example.com:8080'})
|
553 | 556 |
|
| 557 | + def test_respect_proxy_env_on_send_self_prepared_request(self, httpbin): |
| 558 | + with override_environ(http_proxy=INVALID_PROXY): |
| 559 | + with pytest.raises(ProxyError): |
| 560 | + session = requests.Session() |
| 561 | + request = requests.Request('GET', httpbin()) |
| 562 | + session.send(request.prepare()) |
| 563 | + |
| 564 | + def test_respect_proxy_env_on_send_session_prepared_request(self, httpbin): |
| 565 | + with override_environ(http_proxy=INVALID_PROXY): |
| 566 | + with pytest.raises(ProxyError): |
| 567 | + session = requests.Session() |
| 568 | + request = requests.Request('GET', httpbin()) |
| 569 | + prepared = session.prepare_request(request) |
| 570 | + session.send(prepared) |
| 571 | + |
| 572 | + def test_respect_proxy_env_on_send_with_redirects(self, httpbin): |
| 573 | + with override_environ(http_proxy=INVALID_PROXY): |
| 574 | + with pytest.raises(ProxyError): |
| 575 | + session = requests.Session() |
| 576 | + url = httpbin('redirect/1') |
| 577 | + print(url) |
| 578 | + request = requests.Request('GET', url) |
| 579 | + session.send(request.prepare()) |
| 580 | + |
| 581 | + def test_respect_proxy_env_on_get(self, httpbin): |
| 582 | + with override_environ(http_proxy=INVALID_PROXY): |
| 583 | + with pytest.raises(ProxyError): |
| 584 | + session = requests.Session() |
| 585 | + session.get(httpbin()) |
| 586 | + |
| 587 | + def test_respect_proxy_env_on_request(self, httpbin): |
| 588 | + with override_environ(http_proxy=INVALID_PROXY): |
| 589 | + with pytest.raises(ProxyError): |
| 590 | + session = requests.Session() |
| 591 | + session.request(method='GET', url=httpbin()) |
| 592 | + |
554 | 593 | def test_basicauth_with_netrc(self, httpbin):
|
555 | 594 | auth = ('user', 'pass')
|
556 | 595 | wrong_auth = ('wronguser', 'wrongpass')
|
|
0 commit comments