Skip to content

Commit ccbc5fb

Browse files
author
Noah Gorny
committed
tests: session: Remake test_insecure_host into test_trusted_host
1 parent 4632fe3 commit ccbc5fb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

tests/unit/test_network_session.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,24 @@ def test_http_cache_is_not_enabled(self, tmpdir):
7272

7373
assert not hasattr(session.adapters["http://"], "cache")
7474

75-
def test_insecure_host_adapter(self, tmpdir):
75+
@pytest.mark.parametrize("cache_trusted_hosts", [True, False])
76+
def test_trusted_hosts_adapter(self, tmpdir, cache_trusted_hosts):
7677
session = PipSession(
7778
cache=tmpdir.joinpath("test-cache"),
7879
trusted_hosts=["example.com"],
80+
cache_trusted_hosts=cache_trusted_hosts,
7981
)
8082

8183
assert "https://example.com/" in session.adapters
8284
# Check that the "port wildcard" is present.
8385
assert "https://example.com:" in session.adapters
84-
# Check that the cache isn't enabled.
85-
assert not hasattr(session.adapters["https://example.com/"], "cache")
86+
# Check that the cache is enabled only when
87+
# "cache_trusted_host" is enabled.
88+
assert (
89+
cache_trusted_host == (
90+
hasattr(session.adapters["https://example.com/"], "cache")
91+
)
92+
)
8693

8794
def test_add_trusted_host(self):
8895
# Leave a gap to test how the ordering is affected.

0 commit comments

Comments
 (0)