|
11 | 11 | DEFAULT_TIMEOUT = 10 |
12 | 12 |
|
13 | 13 |
|
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 | | - |
28 | 14 | @when( |
29 | 15 | "I request the {endpoint} endpoint in {hostname:w}:{port:d} with {body} in the body" |
30 | 16 | ) |
@@ -61,7 +47,7 @@ def request_endpoint_with_json( |
61 | 47 | # perform REST API call |
62 | 48 | context.response = requests.get( |
63 | 49 | f"http://{hostname}:{port}/{endpoint}", |
64 | | - json=_safe_json_loads(context.text), |
| 50 | + json=json.loads(context.text), |
65 | 51 | timeout=DEFAULT_TIMEOUT, |
66 | 52 | ) |
67 | 53 |
|
@@ -154,7 +140,7 @@ def check_response_body_schema(context: Context) -> None: |
154 | 140 | """ |
155 | 141 | assert context.response is not None, "Request needs to be performed first" |
156 | 142 | 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) |
158 | 144 | body = context.response.json() |
159 | 145 |
|
160 | 146 | validate_json(schema, body) |
@@ -198,7 +184,7 @@ def check_prediction_result_ignoring_field(context: Context, field: str) -> None |
198 | 184 | """ |
199 | 185 | assert context.response is not None, "Request needs to be performed first" |
200 | 186 | 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() |
202 | 188 | result = context.response.json().copy() |
203 | 189 |
|
204 | 190 | expected_body.pop(field, None) |
@@ -269,7 +255,7 @@ def access_rest_api_endpoint_post(context: Context, endpoint: str) -> None: |
269 | 255 | url = base + path |
270 | 256 |
|
271 | 257 | assert context.text is not None, "Payload needs to be specified" |
272 | | - data = _safe_json_loads(context.text) |
| 258 | + data = json.loads(context.text) |
273 | 259 | # initial value |
274 | 260 | context.response = None |
275 | 261 |
|
|
0 commit comments