Skip to content

Commit 8af6087

Browse files
committed
use only proper json values
1 parent 591f4ab commit 8af6087

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

tests/e2e/features/steps/common_http.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,6 @@
1111
DEFAULT_TIMEOUT = 10
1212

1313

14-
def _safe_json_loads(json_str):
15-
"""Safely parse JSON string, handling Python boolean literals.
16-
17-
Handles both standard JSON boolean literals (true/false) and
18-
Python boolean literals (True/False) for robust parsing.
19-
"""
20-
try:
21-
return json.loads(json_str)
22-
except json.JSONDecodeError:
23-
# Handle Python boolean literals in JSON
24-
normalized_str = json_str.replace("True", "true").replace("False", "false")
25-
return json.loads(normalized_str)
26-
27-
2814
@when(
2915
"I request the {endpoint} endpoint in {hostname:w}:{port:d} with {body} in the body"
3016
)
@@ -61,7 +47,7 @@ def request_endpoint_with_json(
6147
# perform REST API call
6248
context.response = requests.get(
6349
f"http://{hostname}:{port}/{endpoint}",
64-
json=_safe_json_loads(context.text),
50+
json=json.loads(context.text),
6551
timeout=DEFAULT_TIMEOUT,
6652
)
6753

@@ -154,7 +140,7 @@ def check_response_body_schema(context: Context) -> None:
154140
"""
155141
assert context.response is not None, "Request needs to be performed first"
156142
assert context.text is not None, "Response does not contain any payload"
157-
schema = _safe_json_loads(context.text)
143+
schema = json.loads(context.text)
158144
body = context.response.json()
159145

160146
validate_json(schema, body)
@@ -198,7 +184,7 @@ def check_prediction_result_ignoring_field(context: Context, field: str) -> None
198184
"""
199185
assert context.response is not None, "Request needs to be performed first"
200186
assert context.text is not None, "Response does not contain any payload"
201-
expected_body = _safe_json_loads(context.text).copy()
187+
expected_body = json.loads(context.text).copy()
202188
result = context.response.json().copy()
203189

204190
expected_body.pop(field, None)
@@ -269,7 +255,7 @@ def access_rest_api_endpoint_post(context: Context, endpoint: str) -> None:
269255
url = base + path
270256

271257
assert context.text is not None, "Payload needs to be specified"
272-
data = _safe_json_loads(context.text)
258+
data = json.loads(context.text)
273259
# initial value
274260
context.response = None
275261

0 commit comments

Comments
 (0)