Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: make urlllib3 transport tests more robust against local env #1969

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions tests/transports/test_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,38 +115,46 @@ def test_generic_error(mock_urlopen, elasticapm_client):


def test_http_proxy_environment_variable(elasticapm_client):
with mock.patch.dict("os.environ", {"HTTP_PROXY": "http://example.com"}):
with mock.patch.dict("os.environ", {"HTTP_PROXY": "http://example.com"}, clear=True):
transport = Transport("http://localhost:9999", client=elasticapm_client)
assert isinstance(transport.http, urllib3.ProxyManager)


def test_https_proxy_environment_variable(elasticapm_client):
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com"}):
with mock.patch.dict(
"os.environ",
{
"HTTPS_PROXY": "https://example.com",
},
clear=True,
):
transport = Transport("http://localhost:9999", client=elasticapm_client)
assert isinstance(transport.http, urllib3.poolmanager.ProxyManager)


def test_https_proxy_environment_variable_is_preferred(elasticapm_client):
with mock.patch.dict("os.environ", {"https_proxy": "https://example.com", "HTTP_PROXY": "http://example.com"}):
with mock.patch.dict(
"os.environ", {"https_proxy": "https://example.com", "HTTP_PROXY": "http://example.com"}, clear=True
):
transport = Transport("http://localhost:9999", client=elasticapm_client)
assert isinstance(transport.http, urllib3.poolmanager.ProxyManager)
assert transport.http.proxy.scheme == "https"


def test_no_proxy_star(elasticapm_client):
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "*"}):
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "*"}, clear=True):
transport = Transport("http://localhost:9999", client=elasticapm_client)
assert not isinstance(transport.http, urllib3.poolmanager.ProxyManager)


def test_no_proxy_host(elasticapm_client):
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "localhost"}):
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "localhost"}, clear=True):
transport = Transport("http://localhost:9999", client=elasticapm_client)
assert not isinstance(transport.http, urllib3.poolmanager.ProxyManager)


def test_no_proxy_all(elasticapm_client):
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "*"}):
with mock.patch.dict("os.environ", {"HTTPS_PROXY": "https://example.com", "NO_PROXY": "*"}, clear=True):
transport = Transport("http://localhost:9999", client=elasticapm_client)
assert not isinstance(transport.http, urllib3.poolmanager.ProxyManager)

Expand Down
Loading