Browse Source
Add test for JSON decode error handling in long documents with early errors.
pull/14089/head
Arif Dogan
9 months ago
No known key found for this signature in database
GPG Key ID: A2131177E83422CE
1 changed files with
18 additions and
0 deletions
-
tests/test_json_error_improvements.py
|
|
|
@ -121,3 +121,21 @@ def test_json_decode_error_unclosed_brace(): |
|
|
|
assert "column" in error["msg"].lower() |
|
|
|
assert error["type"] == "json_invalid" |
|
|
|
assert "position" in error["ctx"] |
|
|
|
|
|
|
|
|
|
|
|
def test_json_decode_error_in_middle_of_long_document(): |
|
|
|
# Create a JSON with error early in a long document (need >40 chars after error) |
|
|
|
# The error is at position for "invalid" which needs at least 41 chars after it |
|
|
|
long_json = '{"field": invalid, "padding_field": "this needs to be long enough that we have more than forty characters after the error position"}' |
|
|
|
|
|
|
|
response = client.post( |
|
|
|
"/items/", content=long_json, headers={"Content-Type": "application/json"} |
|
|
|
) |
|
|
|
|
|
|
|
assert response.status_code == 422 |
|
|
|
error = response.json()["detail"][0] |
|
|
|
|
|
|
|
# The error snippet should have "..." at the end since error is early in doc |
|
|
|
assert error["input"].endswith("...") |
|
|
|
assert "invalid" in error["input"] |
|
|
|
assert error["type"] == "json_invalid" |
|
|
|
|