TestRequests Class — requests Architecture
Architecture documentation for the TestRequests class in test_requests.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 22b80b19_26d4_cd0e_c476_3edf87b3df14["TestRequests"] 65d2dd82_e753_b9d1_adf3_5ea1bae628b1["ProxyError"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|extends| 65d2dd82_e753_b9d1_adf3_5ea1bae628b1 a97e2627_84b9_6952_72a0_d90b0f9f72de["InvalidProxyURL"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|extends| a97e2627_84b9_6952_72a0_d90b0f9f72de 203d0b15_f81d_205a_6390_225bb6cd24cb["MyCookiePolicy"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|extends| 203d0b15_f81d_205a_6390_225bb6cd24cb 5f5c4495_052d_a9c8_2212_6ab9998c0ab5["InvalidHeader"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|extends| 5f5c4495_052d_a9c8_2212_6ab9998c0ab5 1acb95ca_42ed_5e1e_3c56_26ad82925afd["UnrewindableBodyError"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|extends| 1acb95ca_42ed_5e1e_3c56_26ad82925afd 69ebfd6f_8f0c_4586_0c19_2c348e1a42a2["test_requests.py"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|defined in| 69ebfd6f_8f0c_4586_0c19_2c348e1a42a2 370b450c_59cb_a601_bc6b_797d12132609["test_entry_points()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|method| 370b450c_59cb_a601_bc6b_797d12132609 054bc26e_102a_6e2b_b75a_fa09cf2d39dd["test_invalid_url()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|method| 054bc26e_102a_6e2b_b75a_fa09cf2d39dd 51ce3f3b_665e_ae16_529c_b82b02cae955["test_basic_building()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|method| 51ce3f3b_665e_ae16_529c_b82b02cae955 eaf2ed35_9d2f_ab61_fa9f_6131aa9dff59["test_no_content_length()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|method| eaf2ed35_9d2f_ab61_fa9f_6131aa9dff59 e5b10392_71db_6b23_e2e2_427fcf86139e["test_no_body_content_length()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|method| e5b10392_71db_6b23_e2e2_427fcf86139e edc59e11_591c_52dc_d9eb_6ef2000a8874["test_empty_content_length()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|method| edc59e11_591c_52dc_d9eb_6ef2000a8874 b9777d6c_530f_b660_da54_18c2e894667b["test_override_content_length()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|method| b9777d6c_530f_b660_da54_18c2e894667b b2825b66_5b01_c95c_9e73_1ed910669da3["test_path_is_not_double_encoded()"] 22b80b19_26d4_cd0e_c476_3edf87b3df14 -->|method| b2825b66_5b01_c95c_9e73_1ed910669da3
Relationship Graph
Source Code
tests/test_requests.py lines 84–2274
class TestRequests:
digest_auth_algo = ("MD5", "SHA-256", "SHA-512")
def test_entry_points(self):
requests.session
requests.session().get
requests.session().head
requests.get
requests.head
requests.put
requests.patch
requests.post
# Not really an entry point, but people rely on it.
from requests.packages.urllib3.poolmanager import PoolManager # noqa:F401
@pytest.mark.parametrize(
"exception, url",
(
(MissingSchema, "hiwpefhipowhefopw"),
(InvalidSchema, "localhost:3128"),
(InvalidSchema, "localhost.localdomain:3128/"),
(InvalidSchema, "10.122.1.1:3128/"),
(InvalidURL, "http://"),
(InvalidURL, "http://*example.com"),
(InvalidURL, "http://.example.com"),
),
)
def test_invalid_url(self, exception, url):
with pytest.raises(exception):
requests.get(url)
def test_basic_building(self):
req = requests.Request()
req.url = "http://kennethreitz.org/"
req.data = {"life": "42"}
pr = req.prepare()
assert pr.url == req.url
assert pr.body == "life=42"
@pytest.mark.parametrize("method", ("GET", "HEAD"))
def test_no_content_length(self, httpbin, method):
req = requests.Request(method, httpbin(method.lower())).prepare()
assert "Content-Length" not in req.headers
@pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))
def test_no_body_content_length(self, httpbin, method):
req = requests.Request(method, httpbin(method.lower())).prepare()
assert req.headers["Content-Length"] == "0"
@pytest.mark.parametrize("method", ("POST", "PUT", "PATCH", "OPTIONS"))
def test_empty_content_length(self, httpbin, method):
req = requests.Request(method, httpbin(method.lower()), data="").prepare()
assert req.headers["Content-Length"] == "0"
def test_override_content_length(self, httpbin):
headers = {"Content-Length": "not zero"}
r = requests.Request("POST", httpbin("post"), headers=headers).prepare()
assert "Content-Length" in r.headers
assert r.headers["Content-Length"] == "not zero"
def test_path_is_not_double_encoded(self):
request = requests.Request("GET", "http://0.0.0.0/get/test case").prepare()
assert request.path_url == "/get/test%20case"
@pytest.mark.parametrize(
"url, expected",
(
(
"http://example.com/path#fragment",
"http://example.com/path?a=b#fragment",
),
(
"http://example.com/path?key=value#fragment",
"http://example.com/path?key=value&a=b#fragment",
),
),
)
def test_params_are_added_before_fragment(self, url, expected):
request = requests.Request("GET", url, params={"a": "b"}).prepare()
Domain
Defined In
Source
Frequently Asked Questions
What is the TestRequests class?
TestRequests is a class in the requests codebase, defined in tests/test_requests.py.
Where is TestRequests defined?
TestRequests is defined in tests/test_requests.py at line 84.
What does TestRequests extend?
TestRequests extends ProxyError, InvalidProxyURL, MyCookiePolicy, InvalidHeader, UnrewindableBodyError.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free