mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Add test for Session.get_adapter() prefix matching
This commit is contained in:
@@ -1351,6 +1351,24 @@ class TestRequests:
|
||||
assert 'http://' in s2.adapters
|
||||
assert 'https://' in s2.adapters
|
||||
|
||||
def test_session_get_adapter_prefix_matching(self, httpbin):
|
||||
prefix = 'https://example.com'
|
||||
more_specific_prefix = prefix + '/some/path'
|
||||
|
||||
url_matching_only_prefix = prefix + '/another/path'
|
||||
url_matching_more_specific_prefix = more_specific_prefix + '/longer/path'
|
||||
url_not_matching_prefix = 'https://another.example.com/'
|
||||
|
||||
s = requests.Session()
|
||||
prefix_adapter = HTTPAdapter()
|
||||
more_specific_prefix_adapter = HTTPAdapter()
|
||||
s.mount(prefix, prefix_adapter)
|
||||
s.mount(more_specific_prefix, more_specific_prefix_adapter)
|
||||
|
||||
assert s.get_adapter(url_matching_only_prefix) is prefix_adapter
|
||||
assert s.get_adapter(url_matching_more_specific_prefix) is more_specific_prefix_adapter
|
||||
assert s.get_adapter(url_not_matching_prefix) not in (prefix_adapter, more_specific_prefix_adapter)
|
||||
|
||||
def test_session_get_adapter_prefix_matching_is_case_insensitive(self, httpbin):
|
||||
mixed_case_prefix = 'hTtPs://eXamPle.CoM/MixEd_CAse_PREfix'
|
||||
url_matching_prefix = mixed_case_prefix + '/full_url'
|
||||
|
||||
Reference in New Issue
Block a user