Repository: encode/httpx
Pull request #3375 (2024-10-28 16:34:36)

Cleanup unneccessary test case
This test case issues a warning on 3.11+

```
tests/client/test_auth.py:273: netrc files without a password are invalid with Python < 3.11
```

Let's just tidy this case up completely.


Patch:
diff --git a/httpx/_urls.py b/httpx/_urls.py
index bfc0e9e..7976cb1 100644
--- a/httpx/_urls.py
+++ b/httpx/_urls.py
@@ -12,20 +12,6 @@ from ._utils import primitive_value_to_str
 __all__ = ["URL", "QueryParams"]
 
 
-# To urlencode query parameters, we use the whatwg query percent-encode set
-# and additionally escape U+0025 (%), U+0026 (&), U+002B (+) and U+003D (=).
-
-# https://url.spec.whatwg.org/#percent-encoded-bytes
-
-URLENCODE_SAFE = "".join(
-    [
-        chr(i)
-        for i in range(0x20, 0x7F)
-        if i not in (0x20, 0x22, 0x23, 0x25, 0x26, 0x2B, 0x3C, 0x3D, 0x3E)
-    ]
-)
-
-
 class URL:
     """
     url = httpx.URL("HTTPS://jo%40email.com:a%20secret@müller.de:1234/pa%20th?search=ab#anchorlink")
@@ -619,7 +605,7 @@ class QueryParams(typing.Mapping[str, str]):
         return sorted(self.multi_items()) == sorted(other.multi_items())
 
     def __str__(self) -> str:
-        return urlencode(self.multi_items(), safe=URLENCODE_SAFE)
+        return urlencode(self.multi_items())
 
     def __repr__(self) -> str:
         class_name = self.__class__.__name__


Test patch:
diff --git a/tests/client/test_auth.py b/tests/client/test_auth.py
index b3aeaf4..7638b8b 100644
--- a/tests/client/test_auth.py
+++ b/tests/client/test_auth.py
@@ -270,29 +270,6 @@ def test_netrc_auth_credentials_do_not_exist() -> None:
     assert response.json() == {"auth": None}
 
 
-@pytest.mark.skipif(
-    sys.version_info < (3, 11),
-    reason="netrc files without a password are invalid with Python < 3.11",
-)
-def test_netrc_auth_nopassword() -> None:  # pragma: no cover
-    """
-    Python has different netrc parsing behaviours with different versions.
-    For Python 3.11+ a netrc file with no password is valid. In this case
-    we want to check that we allow the netrc auth, and simply don't provide
-    any credentials in the request.
-    """
-    netrc_file = str(FIXTURES_DIR / ".netrc-nopassword")
-    url = "http://example.org"
-    app = App()
-    auth = httpx.NetRCAuth(netrc_file)
-
-    with httpx.Client(transport=httpx.MockTransport(app), auth=auth) as client:
-        response = client.get(url)
-
-    assert response.status_code == 200
-    assert response.json() == {"auth": None}
-
-
 @pytest.mark.skipif(
     sys.version_info >= (3, 11),
     reason="netrc files without a password are valid from Python >= 3.11",
diff --git a/tests/models/test_url.py b/tests/models/test_url.py
index d32ed52..03072e8 100644
--- a/tests/models/test_url.py
+++ b/tests/models/test_url.py
@@ -148,7 +148,7 @@ def test_url_query_encoding():
     assert url.raw_path == b"/?a=b+c&d=e/f"
 
     url = httpx.URL("https://www.example.com/", params={"a": "b c", "d": "e/f"})
-    assert url.raw_path == b"/?a=b+c&d=e/f"
+    assert url.raw_path == b"/?a=b+c&d=e%2Ff"
 
 
 def test_url_params():
@@ -309,7 +309,7 @@ def test_param_with_existing_escape_requires_encoding():
     # even if they include a valid escape sequence.
     # We want to match browser form behaviour here.
     url = httpx.URL("http://webservice", params={"u": "http://example.com?q=foo%2Fa"})
-    assert str(url) == "http://webservice?u=http://example.com?q%3Dfoo%252Fa"
+    assert str(url) == "http://webservice?u=http%3A%2F%2Fexample.com%3Fq%3Dfoo%252Fa"
 
 
 # Tests for query parameter percent encoding.