]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Drop private import of 'format_form_param' from tests (#2500)
authorTom Christie <tom@tomchristie.com>
Mon, 12 Dec 2022 16:31:29 +0000 (16:31 +0000)
committerGitHub <noreply@github.com>
Mon, 12 Dec 2022 16:31:29 +0000 (16:31 +0000)
* Drop private import of 'format_form_param' from tests

* Drop unused code path

httpx/_utils.py
tests/test_multipart.py

index 126936db15876ef18bb21bc0767fdabca553a763..1f64deedcda337d6437b2c9a8ab205cc3ee0fc51 100644 (file)
@@ -81,12 +81,10 @@ def is_known_encoding(encoding: str) -> bool:
     return True
 
 
-def format_form_param(name: str, value: typing.Union[str, bytes]) -> bytes:
+def format_form_param(name: str, value: str) -> bytes:
     """
     Encode a name/value pair within a multipart form.
     """
-    if isinstance(value, bytes):
-        value = value.decode()
 
     def replacer(match: typing.Match[str]) -> str:
         return _HTML5_FORM_ENCODING_REPLACEMENTS[match.group(0)]
index 6d281ed7d09955fbaa90c1548236b9579fa79d7b..99f97c51b5c958dd3fe5501b01e1c62868cd7f22 100644 (file)
@@ -8,7 +8,6 @@ import pytest
 
 import httpx
 from httpx._content import encode_request
-from httpx._utils import format_form_param
 
 
 def echo_request_content(request: httpx.Request) -> httpx.Response:
@@ -437,17 +436,29 @@ def test_multipart_rewinds_files():
 
 class TestHeaderParamHTML5Formatting:
     def test_unicode(self):
-        param = format_form_param("filename", "n\u00e4me")
-        assert param == b'filename="n\xc3\xa4me"'
+        filename = "n\u00e4me"
+        expected = b'filename="n\xc3\xa4me"'
+        files = {"upload": (filename, b"<file content>")}
+        request = httpx.Request("GET", "https://www.example.com", files=files)
+        assert expected in request.read()
 
     def test_ascii(self):
-        param = format_form_param("filename", b"name")
-        assert param == b'filename="name"'
+        filename = "name"
+        expected = b'filename="name"'
+        files = {"upload": (filename, b"<file content>")}
+        request = httpx.Request("GET", "https://www.example.com", files=files)
+        assert expected in request.read()
 
     def test_unicode_escape(self):
-        param = format_form_param("filename", "hello\\world\u0022")
-        assert param == b'filename="hello\\\\world%22"'
+        filename = "hello\\world\u0022"
+        expected = b'filename="hello\\\\world%22"'
+        files = {"upload": (filename, b"<file content>")}
+        request = httpx.Request("GET", "https://www.example.com", files=files)
+        assert expected in request.read()
 
     def test_unicode_with_control_character(self):
-        param = format_form_param("filename", "hello\x1A\x1B\x1C")
-        assert param == b'filename="hello%1A\x1B%1C"'
+        filename = "hello\x1A\x1B\x1C"
+        expected = b'filename="hello%1A\x1B%1C"'
+        files = {"upload": (filename, b"<file content>")}
+        request = httpx.Request("GET", "https://www.example.com", files=files)
+        assert expected in request.read()