Skip to content

Commit

Permalink
tests: network: Add http trusted host adapter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah Gorny committed Jun 10, 2021
1 parent 491b580 commit bde23fe
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/unit/test_network_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -93,14 +94,22 @@ 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)
]
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')
Expand All @@ -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')
Expand All @@ -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):
"""
Expand Down

0 comments on commit bde23fe

Please sign in to comment.