From e14d0801a97a3b538f5b536a7c121433a83bbe28 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 15 Nov 2024 10:23:08 +0000 Subject: [PATCH 1/2] Avoid private imports in test cases --- tests/test_content.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/test_content.py b/tests/test_content.py index 053f52eac4..ef7f13e765 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -4,7 +4,6 @@ import pytest import httpx -from httpx._content import encode_json method = "POST" url = "https://www.example.com" @@ -489,22 +488,18 @@ def test_response_invalid_argument(): def test_ensure_ascii_false_with_french_characters(): data = {"greeting": "Bonjour, ça va ?"} - headers, byte_stream = encode_json(data) - json_output = b"".join(byte_stream).decode("utf-8") - + response = httpx.Response(200, json=data) assert ( - "ça va" in json_output + "ça va" in response.text ), "ensure_ascii=False should preserve French accented characters" assert headers["Content-Type"] == "application/json" def test_separators_for_compact_json(): data = {"clé": "valeur", "liste": [1, 2, 3]} - headers, byte_stream = encode_json(data) - json_output = b"".join(byte_stream).decode("utf-8") - + response = httpx.Response(200, json=data) assert ( - json_output == '{"clé":"valeur","liste":[1,2,3]}' + response.text == '{"clé":"valeur","liste":[1,2,3]}' ), "separators=(',', ':') should produce a compact representation" assert headers["Content-Type"] == "application/json" @@ -516,8 +511,8 @@ def test_allow_nan_false(): with pytest.raises( ValueError, match="Out of range float values are not JSON compliant" ): - encode_json(data_with_nan) + httpx.Response(200, json=data_with_nan) with pytest.raises( ValueError, match="Out of range float values are not JSON compliant" ): - encode_json(data_with_inf) + httpx.Response(200, json=data_with_inf) From d686e43ea1e52c9fa283b592c7423498631c62b8 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Fri, 15 Nov 2024 10:25:28 +0000 Subject: [PATCH 2/2] Update test_content.py --- tests/test_content.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_content.py b/tests/test_content.py index ef7f13e765..f63ec18a6b 100644 --- a/tests/test_content.py +++ b/tests/test_content.py @@ -492,7 +492,7 @@ def test_ensure_ascii_false_with_french_characters(): assert ( "ça va" in response.text ), "ensure_ascii=False should preserve French accented characters" - assert headers["Content-Type"] == "application/json" + assert response.headers["Content-Type"] == "application/json" def test_separators_for_compact_json(): @@ -501,7 +501,7 @@ def test_separators_for_compact_json(): assert ( response.text == '{"clé":"valeur","liste":[1,2,3]}' ), "separators=(',', ':') should produce a compact representation" - assert headers["Content-Type"] == "application/json" + assert response.headers["Content-Type"] == "application/json" def test_allow_nan_false():