Skip to content

Commit b492588

Browse files
committed
test: compare structured request bodies as decoded JSON
1 parent 3f1bfb3 commit b492588

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

end_to_end_tests/functional_tests/generated_code_execution/test_nullable_request_bodies.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
import datetime
33
import inspect
4+
import json
45
import subprocess
56
import sys
67
from typing import Any, get_args
@@ -370,25 +371,23 @@ def test_nullable_model_array_and_nested_fields(self, generated_client: Any) ->
370371
model_endpoint = self._endpoint(generated_client, "nullable_model")
371372
assert _sync_request(model_endpoint, Client).content == b""
372373
assert _sync_request(model_endpoint, Client, body=None).content == b"null"
373-
assert _sync_request(model_endpoint, Client, body=Payload(name="Ada")).content == b'{"name":"Ada"}'
374+
assert json.loads(_sync_request(model_endpoint, Client, body=Payload(name="Ada")).content) == {"name": "Ada"}
374375

375376
array_endpoint = self._endpoint(generated_client, "nullable_array")
376377
assert _sync_request(array_endpoint, Client).content == b""
377378
assert _sync_request(array_endpoint, Client, body=None).content == b"null"
378-
assert _sync_request(array_endpoint, Client, body=[]).content == b"[]"
379-
assert _sync_request(array_endpoint, Client, body=[0, 2]).content == b"[0,2]"
379+
assert json.loads(_sync_request(array_endpoint, Client, body=[]).content) == []
380+
assert json.loads(_sync_request(array_endpoint, Client, body=[0, 2]).content) == [0, 2]
380381

381382
nested_endpoint = self._endpoint(generated_client, "nested_nullable_fields")
382-
assert _sync_request(nested_endpoint, Client, body=NestedPayload()).content == b"{}"
383-
assert (
383+
assert json.loads(_sync_request(nested_endpoint, Client, body=NestedPayload()).content) == {}
384+
assert json.loads(
384385
_sync_request(nested_endpoint, Client, body=NestedPayload(optional_nullable=None)).content
385-
== b'{"optionalNullable":null}'
386-
)
386+
) == {"optionalNullable": None}
387387
date_time = datetime.datetime(2026, 9, 15, 12, 30, tzinfo=datetime.UTC)
388-
assert (
388+
assert json.loads(
389389
_sync_request(nested_endpoint, Client, body=NestedPayload(optional_date_time=date_time)).content
390-
== b'{"optionalDateTime":"2026-09-15T12:30:00+00:00"}'
391-
)
390+
) == {"optionalDateTime": "2026-09-15T12:30:00+00:00"}
392391

393392
def test_async_transport_preserves_presence(self, generated_client: Any) -> None:
394393
Client = generated_client.import_symbol(".client", "Client")

0 commit comments

Comments
 (0)