Skip to content

Commit 96c0e93

Browse files
author
Noah Gorny
committed
tests: network: Add http trusted host adapter tests
1 parent 3555182 commit 96c0e93

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/unit/test_network_session.py

+12
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def test_trusted_hosts_adapter(self, tmpdir):
8282
# Check that the "port wildcard" is present.
8383
assert "https://example.com:" in session.adapters
8484
# Check that the cache is enabled.
85+
assert hasattr(session.adapters["http://example.com/"], "cache")
8586
assert hasattr(session.adapters["https://example.com/"], "cache")
8687

8788
def test_add_trusted_host(self):
@@ -93,12 +94,20 @@ def test_add_trusted_host(self):
9394
prefix3 = "https://host3/"
9495
prefix3_wildcard = "https://host3:"
9596

97+
prefix2_http = "http://host2/"
98+
prefix3_http = "http://host3/"
99+
prefix3_wildcard_http = "http://host3:"
100+
96101
# Confirm some initial conditions as a baseline.
97102
assert session.pip_trusted_origins == [("host1", None), ("host3", None)]
98103
assert session.adapters[prefix3] is trusted_host_adapter
99104
assert session.adapters[prefix3_wildcard] is trusted_host_adapter
100105

106+
assert session.adapters[prefix3_http] is trusted_host_adapter
107+
assert session.adapters[prefix3_wildcard_http] is trusted_host_adapter
108+
101109
assert prefix2 not in session.adapters
110+
assert prefix2_http not in session.adapters
102111

103112
# Test adding a new host.
104113
session.add_trusted_host("host2")
@@ -110,6 +119,7 @@ def test_add_trusted_host(self):
110119
# Check that prefix3 is still present.
111120
assert session.adapters[prefix3] is trusted_host_adapter
112121
assert session.adapters[prefix2] is trusted_host_adapter
122+
assert session.adapters[prefix2_http] is trusted_host_adapter
113123

114124
# Test that adding the same host doesn't create a duplicate.
115125
session.add_trusted_host("host3")
@@ -121,13 +131,15 @@ def test_add_trusted_host(self):
121131

122132
session.add_trusted_host("host4:8080")
123133
prefix4 = "https://host4:8080/"
134+
prefix4_http = "http://host4:8080/"
124135
assert session.pip_trusted_origins == [
125136
("host1", None),
126137
("host3", None),
127138
("host2", None),
128139
("host4", 8080),
129140
]
130141
assert session.adapters[prefix4] is trusted_host_adapter
142+
assert session.adapters[prefix4_http] is trusted_host_adapter
131143

132144
def test_add_trusted_host__logging(self, caplog):
133145
"""

0 commit comments

Comments
 (0)