예제 #1
0
def test_proxies_from_env(monkeypatch, protocol) -> None:
    url = URL('http://aiohttp.io/path')
    monkeypatch.setenv(protocol + '_proxy', str(url))
    ret = helpers.proxies_from_env()
    assert ret.keys() == {protocol}
    assert ret[protocol].proxy == url
    assert ret[protocol].proxy_auth is None
예제 #2
0
def test_proxies_from_env_http_proxy_for_https_proto(mocker) -> None:
    url = URL('http://aiohttp.io/path')
    mocker.patch.dict(os.environ, {'https_proxy': str(url)})
    ret = helpers.proxies_from_env()
    assert ret.keys() == {'https'}
    assert ret['https'].proxy == url
    assert ret['https'].proxy_auth is None
예제 #3
0
def test_proxies_from_env_skipped(caplog, url_input, expected_scheme) -> None:
    url = URL(url_input)
    assert helpers.proxies_from_env() == {}
    assert len(caplog.records) == 1
    log_message = "{proto!s} proxies {url!s} are not supported, ignoring".format(
        proto=expected_scheme.upper(), url=url)
    assert caplog.record_tuples == [("aiohttp.client", 30, log_message)]
예제 #4
0
def test_proxies_from_env_https_proxy_skipped(mocker) -> None:
    url = URL('https://aiohttp.io/path')
    mocker.patch.dict(os.environ, {'https_proxy': str(url)})
    log = mocker.patch('aiohttp.log.client_logger.warning')
    assert helpers.proxies_from_env() == {}
    log.assert_called_with('HTTPS proxies %s are not supported, ignoring',
                           URL('https://aiohttp.io/path'))
예제 #5
0
def test_proxies_from_env_https_proxy_skipped(mocker):
    url = URL('https://aiohttp.io/path')
    mocker.patch.dict(os.environ, {'https_proxy': str(url)})
    log = mocker.patch('aiohttp.log.client_logger.warning')
    assert helpers.proxies_from_env() == {}
    log.assert_called_with('HTTPS proxies %s are not supported, ignoring',
                           URL('https://aiohttp.io/path'))
예제 #6
0
def test_proxies_from_env_http_proxy_for_https_proto(mocker):
    url = URL('http://aiohttp.io/path')
    mocker.patch.dict(os.environ, {'https_proxy': str(url)})
    ret = helpers.proxies_from_env()
    assert ret.keys() == {'https'}
    assert ret['https'].proxy == url
    assert ret['https'].proxy_auth is None
예제 #7
0
def test_proxies_from_env_skipped(monkeypatch, caplog, protocol) -> None:
    url = URL(protocol + "://aiohttp.io/path")
    monkeypatch.setenv(protocol + "_proxy", str(url))
    assert helpers.proxies_from_env() == {}
    assert len(caplog.records) == 1
    log_message = f"{protocol.upper()!s} proxies {url!s} are not supported, ignoring"
    assert caplog.record_tuples == [("aiohttp.client", 30, log_message)]
예제 #8
0
def test_proxies_from_env_skipped(monkeypatch, caplog, protocol) -> None:
    url = URL(protocol + '://aiohttp.io/path')
    monkeypatch.setenv(protocol + '_proxy', str(url))
    assert helpers.proxies_from_env() == {}
    assert len(caplog.records) == 1
    log_message = (
        '{proto!s} proxies {url!s} are not supported, ignoring'.format(
            proto=protocol.upper(), url=url))
    assert caplog.record_tuples == [('aiohttp.client', 30, log_message)]
예제 #9
0
def test_proxies_from_env_http_with_auth(url_input, expected_scheme) -> None:
    url = URL("http://*****:*****@aiohttp.io/path")
    ret = helpers.proxies_from_env()
    assert ret.keys() == {expected_scheme}
    assert ret[expected_scheme].proxy == url.with_user(None)
    proxy_auth = ret[expected_scheme].proxy_auth
    assert proxy_auth.login == "user"
    assert proxy_auth.password == "pass"
    assert proxy_auth.encoding == "latin1"
예제 #10
0
def test_proxies_from_env_http_with_auth(mocker) -> None:
    url = URL('http://*****:*****@aiohttp.io/path')
    mocker.patch.dict(os.environ, {'http_proxy': str(url)})
    ret = helpers.proxies_from_env()
    assert ret.keys() == {'http'}
    assert ret['http'].proxy == url.with_user(None)
    proxy_auth = ret['http'].proxy_auth
    assert proxy_auth.login == 'user'
    assert proxy_auth.password == 'pass'
    assert proxy_auth.encoding == 'latin1'
예제 #11
0
def test_proxies_from_env_http_with_auth(mocker) -> None:
    url = URL("http://*****:*****@aiohttp.io/path")
    mocker.patch.dict(os.environ, {"http_proxy": str(url)})
    ret = helpers.proxies_from_env()
    assert ret.keys() == {"http"}
    assert ret["http"].proxy == url.with_user(None)
    proxy_auth = ret["http"].proxy_auth
    assert proxy_auth.login == "user"
    assert proxy_auth.password == "pass"
    assert proxy_auth.encoding == "latin1"
예제 #12
0
def test_proxies_from_env_http_with_auth(mocker):
    url = URL('http://*****:*****@aiohttp.io/path')
    mocker.patch.dict(os.environ, {'http_proxy': str(url)})
    ret = helpers.proxies_from_env()
    assert ret.keys() == {'http'}
    assert ret['http'].proxy == url.with_user(None)
    proxy_auth = ret['http'].proxy_auth
    assert proxy_auth.login == 'user'
    assert proxy_auth.password == 'pass'
    assert proxy_auth.encoding == 'latin1'
예제 #13
0
 def _proxy_from_env(scheme):
     if scheme == 'wss':
         scheme = 'https'
     if scheme == 'ws':
         scheme = 'http'
     proxies = proxies_from_env()
     proxy_info = proxies.get(scheme)
     if proxy_info:
         return proxy_info.proxy, proxy_info.proxy_auth
     else:
         return None, None
예제 #14
0
def test_proxies_from_env(url_input, expected_scheme) -> None:
    url = URL(url_input)
    ret = helpers.proxies_from_env()
    assert ret.keys() == {expected_scheme}
    assert ret[expected_scheme].proxy == url
    assert ret[expected_scheme].proxy_auth is None