From bde23fe68424194e2fb7f6c352e3d1efcd20bce9 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 11 Jun 2021 02:43:19 +0300 Subject: [PATCH] tests: network: Add http trusted host adapter tests --- tests/unit/test_network_session.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/unit/test_network_session.py b/tests/unit/test_network_session.py index 044d1fb923b..d694f3cff4f 100644 --- a/tests/unit/test_network_session.py +++ b/tests/unit/test_network_session.py @@ -82,6 +82,7 @@ def test_trusted_hosts_adapter(self, tmpdir): # Check that the "port wildcard" is present. assert "https://example.com:" in session.adapters # Check that the cache is enabled. + assert hasattr(session.adapters["http://example.com/"], "cache") assert hasattr(session.adapters["https://example.com/"], "cache") def test_add_trusted_host(self): @@ -93,6 +94,10 @@ def test_add_trusted_host(self): prefix3 = 'https://host3/' prefix3_wildcard = 'https://host3:' + prefix2_http = 'http://host2/' + prefix3_http = 'http://host3/' + prefix3_wildcard_http = 'http://host3:' + # Confirm some initial conditions as a baseline. assert session.pip_trusted_origins == [ ('host1', None), ('host3', None) @@ -100,7 +105,11 @@ def test_add_trusted_host(self): assert session.adapters[prefix3] is trusted_host_adapter assert session.adapters[prefix3_wildcard] is trusted_host_adapter + assert session.adapters[prefix3_http] is trusted_host_adapter + assert session.adapters[prefix3_wildcard_http] is trusted_host_adapter + assert prefix2 not in session.adapters + assert prefix2_http not in session.adapters # Test adding a new host. session.add_trusted_host('host2') @@ -110,6 +119,7 @@ def test_add_trusted_host(self): # Check that prefix3 is still present. assert session.adapters[prefix3] is trusted_host_adapter assert session.adapters[prefix2] is trusted_host_adapter + assert session.adapters[prefix2_http] is trusted_host_adapter # Test that adding the same host doesn't create a duplicate. session.add_trusted_host('host3') @@ -119,11 +129,13 @@ def test_add_trusted_host(self): session.add_trusted_host('host4:8080') prefix4 = 'https://host4:8080/' + prefix4_http = 'http://host4:8080/' assert session.pip_trusted_origins == [ ('host1', None), ('host3', None), ('host2', None), ('host4', 8080) ] assert session.adapters[prefix4] is trusted_host_adapter + assert session.adapters[prefix4_http] is trusted_host_adapter def test_add_trusted_host__logging(self, caplog): """