Add test for Session.get_adapter() prefix matching

This commit is contained in:
Alvaro Gutierrez Perez
2017-10-19 16:37:09 +02:00
parent af88af64e6
commit e11989e8ec
+18
View File
@@ -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'