summaryrefslogtreecommitdiff
path: root/tests/test_utils.py
diff options
context:
space:
mode:
authorJohn L. Villalovos <john.l.villalovos@intel.com>2016-09-06 16:24:35 -0700
committerJohn L. Villalovos <john.l.villalovos@intel.com>2017-02-10 09:41:54 -0800
commit85400d8d6751071ef78f042d1efa72bdcf76cc0e (patch)
treef16091e1e03e16c65847c196916b329bc1e6cb44 /tests/test_utils.py
parentad65b0cb19124b5ae4dd01bf19d82c16ffb2485d (diff)
downloadpython-requests-85400d8d6751071ef78f042d1efa72bdcf76cc0e.tar.gz
Allow use of 'no_proxy' in the proxies argument
Add the ability to add 'no_proxy' and a value to the 'proxies' dictionary argument. https://github.com/kennethreitz/requests/issues/2817 Closes gh-2817
Diffstat (limited to 'tests/test_utils.py')
-rw-r--r--tests/test_utils.py52
1 files changed, 49 insertions, 3 deletions
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 1edf6218..11ebf617 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -161,7 +161,7 @@ class TestGetEnvironProxies:
'http://localhost.localdomain:5000/v1.0/',
))
def test_bypass(self, url):
- assert get_environ_proxies(url) == {}
+ assert get_environ_proxies(url, no_proxy=None) == {}
@pytest.mark.parametrize(
'url', (
@@ -170,7 +170,32 @@ class TestGetEnvironProxies:
'http://www.requests.com/',
))
def test_not_bypass(self, url):
- assert get_environ_proxies(url) != {}
+ assert get_environ_proxies(url, no_proxy=None) != {}
+
+ @pytest.mark.parametrize(
+ 'url', (
+ 'http://192.168.1.1:5000/',
+ 'http://192.168.1.1/',
+ 'http://www.requests.com/',
+ ))
+ def test_bypass_no_proxy_keyword(self, url):
+ no_proxy = '192.168.1.1,requests.com'
+ assert get_environ_proxies(url, no_proxy=no_proxy) == {}
+
+ @pytest.mark.parametrize(
+ 'url', (
+ 'http://192.168.0.1:5000/',
+ 'http://192.168.0.1/',
+ 'http://172.16.1.1/',
+ 'http://172.16.1.1:5000/',
+ 'http://localhost.localdomain:5000/v1.0/',
+ ))
+ def test_not_bypass_no_proxy_keyword(self, url, monkeypatch):
+ # This is testing that the 'no_proxy' argument overrides the
+ # environment variable 'no_proxy'
+ monkeypatch.setenv('http_proxy', 'http://proxy.example.com:3128/')
+ no_proxy = '192.168.1.1,requests.com'
+ assert get_environ_proxies(url, no_proxy=no_proxy) != {}
class TestIsIPv4Address:
@@ -525,7 +550,7 @@ def test_should_bypass_proxies(url, expected, monkeypatch):
"""
monkeypatch.setenv('no_proxy', '192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1')
monkeypatch.setenv('NO_PROXY', '192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1')
- assert should_bypass_proxies(url) == expected
+ assert should_bypass_proxies(url, no_proxy=None) == expected
@pytest.mark.parametrize(
@@ -553,3 +578,24 @@ def test_add_dict_to_cookiejar(cookiejar):
)
def test_unicode_is_ascii(value, expected):
assert unicode_is_ascii(value) is expected
+
+
+@pytest.mark.parametrize(
+ 'url, expected', (
+ ('http://192.168.0.1:5000/', True),
+ ('http://192.168.0.1/', True),
+ ('http://172.16.1.1/', True),
+ ('http://172.16.1.1:5000/', True),
+ ('http://localhost.localdomain:5000/v1.0/', True),
+ ('http://172.16.1.12/', False),
+ ('http://172.16.1.12:5000/', False),
+ ('http://google.com:5000/v1.0/', False),
+ ))
+def test_should_bypass_proxies_no_proxy(
+ url, expected, monkeypatch):
+ """Tests for function should_bypass_proxies to check if proxy
+ can be bypassed or not using the 'no_proxy' argument
+ """
+ no_proxy = '192.168.0.0/24,127.0.0.1,localhost.localdomain,172.16.1.1'
+ # Test 'no_proxy' argument
+ assert should_bypass_proxies(url, no_proxy=no_proxy) == expected