From: Eduardo Enriquez Date: Sun, 30 Aug 2020 06:01:37 +0000 (+0200) Subject: Replace httpx.URL for str in tests (#1237) X-Git-Tag: 0.14.3~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aad820992871a4301ba0e1b639f5d8dce24b5146;p=thirdparty%2Fhttpx.git Replace httpx.URL for str in tests (#1237) Co-authored-by: Eduardo Enriquez (eduzen) --- diff --git a/tests/client/test_client.py b/tests/client/test_client.py index 7d4bdd34..fe427ec6 100644 --- a/tests/client/test_client.py +++ b/tests/client/test_client.py @@ -178,7 +178,7 @@ def test_base_url(server): def test_merge_absolute_url(): client = httpx.Client(base_url="https://www.example.com/") request = client.build_request("GET", "http://www.example.com/") - assert request.url == httpx.URL("http://www.example.com/") + assert request.url == "http://www.example.com/" with pytest.warns(DeprecationWarning): assert not request.url.is_ssl @@ -186,19 +186,19 @@ def test_merge_absolute_url(): def test_merge_relative_url(): client = httpx.Client(base_url="https://www.example.com/") request = client.build_request("GET", "/testing/123") - assert request.url == httpx.URL("https://www.example.com/testing/123") + assert request.url == "https://www.example.com/testing/123" def test_merge_relative_url_with_path(): client = httpx.Client(base_url="https://www.example.com/some/path") request = client.build_request("GET", "/testing/123") - assert request.url == httpx.URL("https://www.example.com/some/path/testing/123") + assert request.url == "https://www.example.com/some/path/testing/123" def test_merge_relative_url_with_dotted_path(): client = httpx.Client(base_url="https://www.example.com/some/path") request = client.build_request("GET", "../testing/123") - assert request.url == httpx.URL("https://www.example.com/some/testing/123") + assert request.url == "https://www.example.com/some/testing/123" def test_pool_limits_deprecated(): diff --git a/tests/client/test_properties.py b/tests/client/test_properties.py index 35d4e376..cb6ee328 100644 --- a/tests/client/test_properties.py +++ b/tests/client/test_properties.py @@ -5,21 +5,21 @@ def test_client_base_url(): client = httpx.Client() client.base_url = "https://www.example.org/" # type: ignore assert isinstance(client.base_url, httpx.URL) - assert client.base_url == httpx.URL("https://www.example.org/") + assert client.base_url == "https://www.example.org/" def test_client_base_url_without_trailing_slash(): client = httpx.Client() client.base_url = "https://www.example.org/path" # type: ignore assert isinstance(client.base_url, httpx.URL) - assert client.base_url == httpx.URL("https://www.example.org/path/") + assert client.base_url == "https://www.example.org/path/" def test_client_base_url_with_trailing_slash(): client = httpx.Client() client.base_url = "https://www.example.org/path/" # type: ignore assert isinstance(client.base_url, httpx.URL) - assert client.base_url == httpx.URL("https://www.example.org/path/") + assert client.base_url == "https://www.example.org/path/" def test_client_headers(): diff --git a/tests/client/test_queryparams.py b/tests/client/test_queryparams.py index 68b936d0..22f715da 100644 --- a/tests/client/test_queryparams.py +++ b/tests/client/test_queryparams.py @@ -46,6 +46,4 @@ def test_client_queryparams_echo(): response = client.get(url, params=request_queryparams) assert response.status_code == 200 - assert response.url == httpx.URL( - "http://example.org/echo_queryparams?first=str&second=dict" - ) + assert response.url == "http://example.org/echo_queryparams?first=str&second=dict" diff --git a/tests/client/test_redirects.py b/tests/client/test_redirects.py index 7fc8d766..b18feee9 100644 --- a/tests/client/test_redirects.py +++ b/tests/client/test_redirects.py @@ -186,7 +186,7 @@ def test_redirect_301(): client = httpx.Client(transport=SyncMockTransport()) response = client.post("https://example.org/redirect_301") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/") + assert response.url == "https://example.org/" assert len(response.history) == 1 @@ -194,7 +194,7 @@ def test_redirect_302(): client = httpx.Client(transport=SyncMockTransport()) response = client.post("https://example.org/redirect_302") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/") + assert response.url == "https://example.org/" assert len(response.history) == 1 @@ -202,7 +202,7 @@ def test_redirect_303(): client = httpx.Client(transport=SyncMockTransport()) response = client.get("https://example.org/redirect_303") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/") + assert response.url == "https://example.org/" assert len(response.history) == 1 @@ -210,13 +210,13 @@ def test_disallow_redirects(): client = httpx.Client(transport=SyncMockTransport()) response = client.post("https://example.org/redirect_303", allow_redirects=False) assert response.status_code == httpx.codes.SEE_OTHER - assert response.url == httpx.URL("https://example.org/redirect_303") + assert response.url == "https://example.org/redirect_303" assert response.is_redirect is True assert len(response.history) == 0 response = response.next() assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/") + assert response.url == "https://example.org/" assert response.is_redirect is False assert len(response.history) == 1 @@ -228,7 +228,7 @@ def test_head_redirect(): client = httpx.Client(transport=SyncMockTransport()) response = client.head("https://example.org/redirect_302") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/") + assert response.url == "https://example.org/" assert response.request.method == "HEAD" assert len(response.history) == 1 assert response.text == "" @@ -238,7 +238,7 @@ def test_relative_redirect(): client = httpx.Client(transport=SyncMockTransport()) response = client.get("https://example.org/relative_redirect") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/") + assert response.url == "https://example.org/" assert len(response.history) == 1 @@ -247,7 +247,7 @@ def test_malformed_redirect(): client = httpx.Client(transport=SyncMockTransport()) response = client.get("http://example.org/malformed_redirect") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org:443/") + assert response.url == "https://example.org:443/" assert len(response.history) == 1 @@ -261,7 +261,7 @@ def test_no_scheme_redirect(): client = httpx.Client(transport=SyncMockTransport()) response = client.get("https://example.org/no_scheme_redirect") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/") + assert response.url == "https://example.org/" assert len(response.history) == 1 @@ -269,7 +269,7 @@ def test_fragment_redirect(): client = httpx.Client(transport=SyncMockTransport()) response = client.get("https://example.org/relative_redirect#fragment") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/#fragment") + assert response.url == "https://example.org/#fragment" assert len(response.history) == 1 @@ -277,14 +277,10 @@ def test_multiple_redirects(): client = httpx.Client(transport=SyncMockTransport()) response = client.get("https://example.org/multiple_redirects?count=20") assert response.status_code == httpx.codes.OK - assert response.url == httpx.URL("https://example.org/multiple_redirects") + assert response.url == "https://example.org/multiple_redirects" assert len(response.history) == 20 - assert response.history[0].url == httpx.URL( - "https://example.org/multiple_redirects?count=20" - ) - assert response.history[1].url == httpx.URL( - "https://example.org/multiple_redirects?count=19" - ) + assert response.history[0].url == "https://example.org/multiple_redirects?count=20" + assert response.history[1].url == "https://example.org/multiple_redirects?count=19" assert len(response.history[0].history) == 0 assert len(response.history[1].history) == 1 @@ -332,7 +328,7 @@ def test_cross_domain_redirect(): url = "https://example.com/cross_domain" headers = {"Authorization": "abc"} response = client.get(url, headers=headers) - assert response.url == httpx.URL("https://example.org/cross_domain_target") + assert response.url == "https://example.org/cross_domain_target" assert "authorization" not in response.json()["headers"] @@ -341,7 +337,7 @@ def test_same_domain_redirect(): url = "https://example.org/cross_domain" headers = {"Authorization": "abc"} response = client.get(url, headers=headers) - assert response.url == httpx.URL("https://example.org/cross_domain_target") + assert response.url == "https://example.org/cross_domain_target" assert response.json()["headers"]["authorization"] == "abc" @@ -353,7 +349,7 @@ def test_body_redirect(): url = "https://example.org/redirect_body" data = b"Example request body" response = client.post(url, data=data) - assert response.url == httpx.URL("https://example.org/redirect_body_target") + assert response.url == "https://example.org/redirect_body_target" assert response.json()["body"] == "Example request body" assert "content-length" in response.json()["headers"] @@ -366,7 +362,7 @@ def test_no_body_redirect(): url = "https://example.org/redirect_no_body" data = b"Example request body" response = client.post(url, data=data) - assert response.url == httpx.URL("https://example.org/redirect_body_target") + assert response.url == "https://example.org/redirect_body_target" assert response.json()["body"] == "" assert "content-length" not in response.json()["headers"] @@ -395,7 +391,7 @@ def test_cross_subdomain_redirect(): client = httpx.Client(transport=SyncMockTransport()) url = "https://example.com/cross_subdomain" response = client.get(url) - assert response.url == httpx.URL("https://www.example.org/cross_subdomain") + assert response.url == "https://www.example.org/cross_subdomain" class MockCookieTransport(httpcore.SyncHTTPTransport):