示例#1
0
 def test_override_env_proxy_and_go_direct(self, monkeypatch):
     """Ensure that it's possible to ignore environment proxy settings for a request."""
     monkeypatch.setenv('HTTP_PROXY', 'http://env')
     sess = requests.Session()
     settings = sess.merge_environment_settings(arbitrary_url, {'http': None}, False, False, False)
     assert settings['proxies'] == {}  # requests.session.merge_setting removes entries with None value.
     assert not select_proxy(arbitrary_url, settings['proxies'])
示例#2
0
 def test_environment_proxies(self, monkeypatch, request_url, expected_proxies, expected_proxy_selection):
     """Test usage of proxy settings from environment variables, including host exclusions using `NO_PROXY`."""
     monkeypatch.setenv('HTTP_PROXY', 'http://env')
     monkeypatch.setenv('NO_PROXY', 'a.local, .b.local')
     sess = requests.Session()
     settings = sess.merge_environment_settings(request_url, {}, False, False, False)
     assert settings['proxies'] == expected_proxies
     assert select_proxy(request_url, settings['proxies']) == expected_proxy_selection
示例#3
0
def test_select_proxies(url, expected, proxies):
    """Make sure we can select per-host proxies correctly."""
    assert select_proxy(url, proxies) == expected
示例#4
0
def test_select_proxies(url, expected):
    """Make sure we can select per-host proxies correctly."""
    proxies = {'http': 'http://http.proxy',
               'http://some.host': 'http://some.host.proxy'}
    assert select_proxy(url, proxies) == expected
示例#5
0
 def test_supercede_environment_settings(self, monkeypatch):
     monkeypatch.setenv('HTTP_PROXY', 'http://env')
     sess = requests.Session()
     settings = sess.merge_environment_settings(arbitrary_url, {'http': 'http://other'}, False, False, False)
     assert settings['proxies'] == {'http': 'http://other'}
     assert select_proxy(arbitrary_url, settings['proxies']) == 'http://other'