test_custom_redirect_mixin() — requests Function Reference
Architecture documentation for the test_custom_redirect_mixin() function in test_requests.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 35522ba6_f5bf_6605_cbd8_7f96271cd951["test_custom_redirect_mixin()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14["TestRequests"] 35522ba6_f5bf_6605_cbd8_7f96271cd951 -->|defined in| 22b80b19_26d4_cd0e_c476_3edf87b3df14 b05faa36_98b6_6ce8_ee15_eea2e0931c8e["get_redirect_target()"] 35522ba6_f5bf_6605_cbd8_7f96271cd951 -->|calls| b05faa36_98b6_6ce8_ee15_eea2e0931c8e style 35522ba6_f5bf_6605_cbd8_7f96271cd951 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
tests/test_requests.py lines 2232–2274
def test_custom_redirect_mixin(self, httpbin):
"""Tests a custom mixin to overwrite ``get_redirect_target``.
Ensures a subclassed ``requests.Session`` can handle a certain type of
malformed redirect responses.
1. original request receives a proper response: 302 redirect
2. following the redirect, a malformed response is given:
status code = HTTP 200
location = alternate url
3. the custom session catches the edge case and follows the redirect
"""
url_final = httpbin("html")
querystring_malformed = urlencode({"location": url_final})
url_redirect_malformed = httpbin("response-headers?%s" % querystring_malformed)
querystring_redirect = urlencode({"url": url_redirect_malformed})
url_redirect = httpbin("redirect-to?%s" % querystring_redirect)
urls_test = [
url_redirect,
url_redirect_malformed,
url_final,
]
class CustomRedirectSession(requests.Session):
def get_redirect_target(self, resp):
# default behavior
if resp.is_redirect:
return resp.headers["location"]
# edge case - check to see if 'location' is in headers anyways
location = resp.headers.get("location")
if location and (location != resp.url):
return location
return None
session = CustomRedirectSession()
r = session.get(urls_test[0])
assert len(r.history) == 2
assert r.status_code == 200
assert r.history[0].status_code == 302
assert r.history[0].is_redirect
assert r.history[1].status_code == 200
assert not r.history[1].is_redirect
assert r.url == urls_test[2]
Domain
Subdomains
Defined In
Calls
Source
Frequently Asked Questions
What does test_custom_redirect_mixin() do?
test_custom_redirect_mixin() is a function in the requests codebase, defined in tests/test_requests.py.
Where is test_custom_redirect_mixin() defined?
test_custom_redirect_mixin() is defined in tests/test_requests.py at line 2232.
What does test_custom_redirect_mixin() call?
test_custom_redirect_mixin() calls 1 function(s): get_redirect_target.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free