-
-
Notifications
You must be signed in to change notification settings - Fork 291
fix: json decode bug #955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: json decode bug #955
Changes from all commits
27754ba
9b3eb76
c45f890
c9d0fb0
6e54b1e
2437c88
9fb7256
2703e06
f80e01d
1f5465e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import pytest | ||
|
||
import json | ||
from integration_tests.helpers.http_methods_helpers import post | ||
|
||
|
||
|
@@ -16,3 +16,32 @@ | |
def test_request(route, body, expected_result): | ||
res = post(route, body) | ||
assert res.text == expected_result | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"route, body, expected_result", | ||
[ | ||
("/sync/request_json/json_type", '{"start": null}', {"start": None}), # null | ||
("/sync/request_json/json_type", '{"hello": "world"', None), # invalid json | ||
("/sync/request_json/json_type", '{"lid":570}', {"lid": 570}), # number key | ||
("/sync/request_json/json_type", '{"lid":-570}', {"lid": -570}), # number key | ||
("/sync/request_json/json_type", '{"lid":570.12}', {"lid": 570.12}), # number key | ||
("/sync/request_json/json_type", "[]", []), # empty Array | ||
("/sync/request_json/json_type", "{}", {}), # empty object | ||
("/sync/request_json/json_type", '"string"', "string"), # string only | ||
("/sync/request_json/json_type", "570", 570), # number only | ||
( | ||
"/sync/request_json/json_type", # object with multiple keys | ||
'{"lid": 570, "start": null, "field_name": "mobile", "field_value": "111000111"}', | ||
{"lid": int(570), "start": None, "field_name": "mobile", "field_value": "111000111"}, | ||
), | ||
("/sync/request_json/json_type", '[{"k":"v"},{"k":null}]', [{"k": "v"}, {"k": None}]), # Array<object> | ||
("/sync/request_json/json_type", '{"key":[{"k":"v"},{"k":null}]}', {"key": [{"k": "v"}, {"k": None}]}), | ||
# Array Key | ||
], | ||
) | ||
def test_request_type(route, body, expected_result): | ||
res = post(route, body) | ||
res_dict = json.loads(res.text) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing error handling: The code unconditionally attempts to parse the response as JSON without any try-except block. This will cause unhandled JSONDecodeError exceptions for invalid JSON responses (like in the test case on line 25), instead of allowing the test to properly verify the error condition.
|
||
# Compare the response dictionary with the expected result | ||
assert res_dict == expected_result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential JSON decoding error: The test case tests invalid JSON input but uses json.loads(res.text) unconditionally in the assertion. This will raise a JSONDecodeError when trying to parse the invalid JSON response, causing the test to fail with an exception rather than reaching the assertion. The test should handle the JSON parsing error gracefully or verify the raw response for invalid JSON cases.
📚 Relevant Docs