Skip to content

Commit f9b4e0b

Browse files
committed
test: Use unittest assertions and requests json= in L0_http boundary helper
Apply review feedback on test_large_string_in_json: - Replace bare assert with self.assertGreaterEqual / self.assertEqual so failures surface through unittest's reporting. - Build the request via requests.post(json=payload) instead of dumping the body and passing data=, which is more explicit about the content type and lets requests handle the Content-Type header. - Rename helper to _build_payload_of_json_size since it now returns the payload dict instead of a serialized body.
1 parent 6a74ad1 commit f9b4e0b

1 file changed

Lines changed: 9 additions & 15 deletions

File tree

qa/L0_http/http_input_size_limit_test.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@ def test_large_input_json(self):
499499
f"Expected shape {[1, shape_size]}, got {result['outputs'][0]['shape']}",
500500
)
501501

502-
def _build_json_string_body_of_size(self, target_size):
503-
"""Build a JSON inference request body that is exactly target_size bytes."""
502+
def _build_payload_of_json_size(self, target_size):
503+
"""Build an inference request payload whose JSON serialization is exactly target_size bytes."""
504504
payload = {
505505
"inputs": [
506506
{
@@ -513,21 +513,17 @@ def _build_json_string_body_of_size(self, target_size):
513513
}
514514
overhead = len(json.dumps(payload))
515515
pad = target_size - overhead
516-
assert pad >= 0, "target_size smaller than payload overhead"
516+
self.assertGreaterEqual(pad, 0, "target_size smaller than payload overhead")
517517
payload["inputs"][0]["data"] = ["A" * pad]
518-
body = json.dumps(payload)
519-
assert len(body) == target_size, (len(body), target_size)
520-
return body
518+
self.assertEqual(len(json.dumps(payload)), target_size)
519+
return payload
521520

522521
def test_large_string_in_json(self):
523522
"""Verify the server's JSON size limit at the byte boundary."""
524523
model = "simple_identity"
525-
headers = {"Content-Type": "application/json"}
526524

527-
body_over = self._build_json_string_body_of_size(DEFAULT_LIMIT_BYTES + 1)
528-
response = requests.post(
529-
self._get_infer_url(model), data=body_over, headers=headers
530-
)
525+
payload_over = self._build_payload_of_json_size(DEFAULT_LIMIT_BYTES + 1)
526+
response = requests.post(self._get_infer_url(model), json=payload_over)
531527
self.assertEqual(
532528
400,
533529
response.status_code,
@@ -540,10 +536,8 @@ def test_large_string_in_json(self):
540536
self.assertIn(" bytes exceeds the maximum allowed input size of ", error_msg)
541537
self.assertIn("Use --http-max-input-size to increase the limit.", error_msg)
542538

543-
body_at = self._build_json_string_body_of_size(DEFAULT_LIMIT_BYTES)
544-
response = requests.post(
545-
self._get_infer_url(model), data=body_at, headers=headers
546-
)
539+
payload_at = self._build_payload_of_json_size(DEFAULT_LIMIT_BYTES)
540+
response = requests.post(self._get_infer_url(model), json=payload_at)
547541
self.assertEqual(
548542
200,
549543
response.status_code,

0 commit comments

Comments
 (0)