def test_https_proxy(): old_env = dict(os.environ) os.environ['HTTPS_PROXY'] = BAD_PROXY_SETTINGS['https'] try: check = AgentCheck() proxies = check.get_instance_proxy({'skip_proxy': True}, 'uri/health') response = requests.get('https://google.com', proxies=proxies) response.raise_for_status() finally: os.environ.clear() os.environ.update(old_env)
def test_https_proxy_fail(): old_env = dict(os.environ) os.environ['HTTPS_PROXY'] = BAD_PROXY_SETTINGS['https'] try: with mock.patch('datadog_checks.checks.AgentCheck._get_requests_proxy', return_value={}): check = AgentCheck() proxies = check.get_instance_proxy({}, 'uri/health') with pytest.raises((ConnectTimeout, ProxyError)): requests.get('https://google.com', timeout=1, proxies=proxies) finally: os.environ.clear() os.environ.update(old_env)
def test_config_no_proxy(): with mock.patch('datadog_checks.checks.AgentCheck._get_requests_proxy', return_value=NO_PROXY_DD_CONFIG_SETTINGS): check = AgentCheck() proxy_results = check.get_instance_proxy({}, 'uri/health') assert 'localhost' in proxy_results['no']
def test_deprecated_no_proxy(): with mock.patch('datadog_checks.checks.AgentCheck._get_requests_proxy', return_value=PROXY_SETTINGS): check = AgentCheck() assert check.get_instance_proxy({'no_proxy': True}, 'uri/health') == SKIP_PROXY_SETTINGS
def test_use_proxy(): with mock.patch('datadog_checks.checks.AgentCheck._get_requests_proxy', return_value=PROXY_SETTINGS): check = AgentCheck() assert check.get_instance_proxy({}, 'uri/health') == PROXY_SETTINGS