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
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
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)]
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'))
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'))
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
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)]
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)]
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"
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'
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"
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'
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
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