From 7f141a209058ba9a42d2c33eccf4a7769f24d080 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Mon, 23 Mar 2020 11:29:58 +0200 Subject: [PATCH] tests: session: Remake test_insecure_host into test_trusted_host --- tests/unit/test_network_session.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_network_session.py b/tests/unit/test_network_session.py index 125ac2d8de2..d56f6462518 100644 --- a/tests/unit/test_network_session.py +++ b/tests/unit/test_network_session.py @@ -72,17 +72,24 @@ def test_http_cache_is_not_enabled(self, tmpdir): assert not hasattr(session.adapters["http://"], "cache") - def test_insecure_host_adapter(self, tmpdir): + @pytest.mark.parametrize("cache_trusted_hosts", [True, False]) + def test_trusted_hosts_adapter(self, tmpdir, cache_trusted_hosts): session = PipSession( cache=tmpdir.joinpath("test-cache"), trusted_hosts=["example.com"], + cache_trusted_hosts=cache_trusted_hosts, ) assert "https://example.com/" in session.adapters # Check that the "port wildcard" is present. assert "https://example.com:" in session.adapters - # Check that the cache isn't enabled. - assert not hasattr(session.adapters["https://example.com/"], "cache") + # Check that the cache is enabled only when + # "cache_trusted_hosts" is enabled. + assert ( + cache_trusted_hosts == ( + hasattr(session.adapters["https://example.com/"], "cache") + ) + ) def test_add_trusted_host(self): # Leave a gap to test how the ordering is affected.