Home / Class/ TestPreparingURLs Class — requests Architecture

TestPreparingURLs Class — requests Architecture

Architecture documentation for the TestPreparingURLs class in test_requests.py from the requests codebase.

Entity Profile

Dependency Diagram

graph TD
  0e391504_f528_a095_5b1a_95d479a82586["TestPreparingURLs"]
  81e04ff9_ba51_0f07_a46e_3550ec714f38["RequestException"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|extends| 81e04ff9_ba51_0f07_a46e_3550ec714f38
  2d14a772_615c_c670_32ea_a875f1f37750["JSONDecodeError"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|extends| 2d14a772_615c_c670_32ea_a875f1f37750
  69ebfd6f_8f0c_4586_0c19_2c348e1a42a2["test_requests.py"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|defined in| 69ebfd6f_8f0c_4586_0c19_2c348e1a42a2
  a52c4073_c3a9_0831_73c5_e7d283dd7bda["test_preparing_url()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| a52c4073_c3a9_0831_73c5_e7d283dd7bda
  7a2cae1a_423d_96c8_66ef_e83dd781abdc["test_preparing_bad_url()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| 7a2cae1a_423d_96c8_66ef_e83dd781abdc
  32c97b5c_5918_281c_e323_ebb2b3446d53["test_redirecting_to_bad_url()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| 32c97b5c_5918_281c_e323_ebb2b3446d53
  3d07ba58_8742_38e0_e23f_a48761711a99["test_url_mutation()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| 3d07ba58_8742_38e0_e23f_a48761711a99
  55f26dae_feeb_cdd2_4546_c009008593a7["test_parameters_for_nonstandard_schemes()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| 55f26dae_feeb_cdd2_4546_c009008593a7
  2b4d42df_edc6_5a53_a4bc_6e331dde94bd["test_post_json_nan()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| 2b4d42df_edc6_5a53_a4bc_6e331dde94bd
  39d9313b_c8e3_3981_3827_9fd6a5822584["test_json_decode_compatibility()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| 39d9313b_c8e3_3981_3827_9fd6a5822584
  85e53dc2_f255_9e17_bb1f_170461f95cd2["test_json_decode_persists_doc_attr()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| 85e53dc2_f255_9e17_bb1f_170461f95cd2
  ca57189a_ad4d_2c3c_0fb2_49eb9dc74383["test_status_code_425()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| ca57189a_ad4d_2c3c_0fb2_49eb9dc74383
  52891849_9721_8d84_aae9_58b8ae0c7cd5["test_different_connection_pool_for_tls_settings_verify_True()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| 52891849_9721_8d84_aae9_58b8ae0c7cd5
  ed2e3b4e_bc4c_1ea0_6cb7_3852cf1f76e7["test_different_connection_pool_for_tls_settings_verify_bundle_expired_cert()"]
  0e391504_f528_a095_5b1a_95d479a82586 -->|method| ed2e3b4e_bc4c_1ea0_6cb7_3852cf1f76e7

Relationship Graph

Source Code

tests/test_requests.py lines 2705–3006

class TestPreparingURLs:
    @pytest.mark.parametrize(
        "url,expected",
        (
            ("http://google.com", "http://google.com/"),
            ("http://ジェーピーニック.jp", "http://xn--hckqz9bzb1cyrb.jp/"),
            ("http://xn--n3h.net/", "http://xn--n3h.net/"),
            ("http://ジェーピーニック.jp".encode(), "http://xn--hckqz9bzb1cyrb.jp/"),
            ("http://straße.de/straße", "http://xn--strae-oqa.de/stra%C3%9Fe"),
            (
                "http://straße.de/straße".encode(),
                "http://xn--strae-oqa.de/stra%C3%9Fe",
            ),
            (
                "http://Königsgäßchen.de/straße",
                "http://xn--knigsgchen-b4a3dun.de/stra%C3%9Fe",
            ),
            (
                "http://Königsgäßchen.de/straße".encode(),
                "http://xn--knigsgchen-b4a3dun.de/stra%C3%9Fe",
            ),
            (b"http://xn--n3h.net/", "http://xn--n3h.net/"),
            (
                b"http://[1200:0000:ab00:1234:0000:2552:7777:1313]:12345/",
                "http://[1200:0000:ab00:1234:0000:2552:7777:1313]:12345/",
            ),
            (
                "http://[1200:0000:ab00:1234:0000:2552:7777:1313]:12345/",
                "http://[1200:0000:ab00:1234:0000:2552:7777:1313]:12345/",
            ),
        ),
    )
    def test_preparing_url(self, url, expected):
        def normalize_percent_encode(x):
            # Helper function that normalizes equivalent
            # percent-encoded bytes before comparisons
            for c in re.findall(r"%[a-fA-F0-9]{2}", x):
                x = x.replace(c, c.upper())
            return x

        r = requests.Request("GET", url=url)
        p = r.prepare()
        assert normalize_percent_encode(p.url) == expected

    @pytest.mark.parametrize(
        "url",
        (
            b"http://*.google.com",
            b"http://*",
            "http://*.google.com",
            "http://*",
            "http://☃.net/",
        ),
    )
    def test_preparing_bad_url(self, url):
        r = requests.Request("GET", url=url)
        with pytest.raises(requests.exceptions.InvalidURL):
            r.prepare()

    @pytest.mark.parametrize("url, exception", (("http://:1", InvalidURL),))
    def test_redirecting_to_bad_url(self, httpbin, url, exception):
        with pytest.raises(exception):
            requests.get(httpbin("redirect-to"), params={"url": url})

    @pytest.mark.parametrize(
        "input, expected",
        (
            (
                b"http+unix://%2Fvar%2Frun%2Fsocket/path%7E",
                "http+unix://%2Fvar%2Frun%2Fsocket/path~",
            ),
            (
                "http+unix://%2Fvar%2Frun%2Fsocket/path%7E",
                "http+unix://%2Fvar%2Frun%2Fsocket/path~",
            ),
            (
                b"mailto:user@example.org",
                "mailto:user@example.org",
            ),
            (
                "mailto:user@example.org",

Domain

Frequently Asked Questions

What is the TestPreparingURLs class?
TestPreparingURLs is a class in the requests codebase, defined in tests/test_requests.py.
Where is TestPreparingURLs defined?
TestPreparingURLs is defined in tests/test_requests.py at line 2705.
What does TestPreparingURLs extend?
TestPreparingURLs extends RequestException, JSONDecodeError.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free