Skip to content

Commit c071f25

Browse files
committed
add unit test for json.JSONDecodeError
1 parent 7ed165e commit c071f25

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/test__helpers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,15 @@ def test_parse_request_body_json_value_error():
642642
assert _helpers._parse_request_body(body, content_type) == body.decode("utf-8")
643643

644644

645+
def test_parse_request_body_json_decode_error():
646+
body = b'{"key": "value"}'
647+
content_type = "application/json"
648+
with mock.patch("json.loads", side_effect=json.JSONDecodeError("msg", "doc", 0)):
649+
# json.loads should raise a JSONDecodeError, and the function should return the
650+
# original string
651+
assert _helpers._parse_request_body(body, content_type) == body.decode("utf-8")
652+
653+
645654
def test_parse_response_json_valid():
646655
class MockResponse:
647656
def json(self):

0 commit comments

Comments
 (0)