Skip to content

Commit b0a817b

Browse files
test: convert _encode_payload output to bytes and assert SEQUENCE contents (#43979)
Address Copilot review feedback on the from_bytes() tests: - Wrap _encode_payload output in bytes() at all four call sites so the tests exercise the documented from_bytes(bytes) contract instead of relying on the function's bytearray runtime return. - Add a content assertion to the SEQUENCE body test so it catches decoding regressions, not just body_type misclassification.
1 parent a468865 commit b0a817b

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

sdk/servicebus/azure-servicebus/tests/test_message.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,11 @@ def test_servicebus_received_message_from_bytes():
384384
data=[b"hello world"],
385385
)
386386

387-
# Encode to bytes then decode via from_bytes
387+
# Encode to bytes then decode via from_bytes.
388+
# _encode_payload returns the bytearray buffer it was given; wrap in bytes()
389+
# so the test exercises the public from_bytes(bytes) contract.
388390
output = bytearray()
389-
payload = _encode_payload(output, original)
391+
payload = bytes(_encode_payload(output, original))
390392
received = ServiceBusReceivedMessage.from_bytes(payload)
391393

392394
# Validate message body
@@ -424,7 +426,7 @@ def test_servicebus_received_message_from_bytes_minimal():
424426

425427
original = PyamqpMessage(data=[b"minimal payload"])
426428
output = bytearray()
427-
payload = _encode_payload(output, original)
429+
payload = bytes(_encode_payload(output, original))
428430
received = ServiceBusReceivedMessage.from_bytes(payload)
429431

430432
body = b"".join(received.body)
@@ -442,7 +444,7 @@ def test_servicebus_received_message_from_bytes_value_body():
442444

443445
original = PyamqpMessage(value={"key": "value"})
444446
output = bytearray()
445-
payload = _encode_payload(output, original)
447+
payload = bytes(_encode_payload(output, original))
446448
received = ServiceBusReceivedMessage.from_bytes(payload)
447449

448450
assert received.body_type == AmqpMessageBodyType.VALUE
@@ -457,10 +459,12 @@ def test_servicebus_received_message_from_bytes_sequence_body():
457459

458460
original = PyamqpMessage(sequence=[1, 2, 3])
459461
output = bytearray()
460-
payload = _encode_payload(output, original)
462+
payload = bytes(_encode_payload(output, original))
461463
received = ServiceBusReceivedMessage.from_bytes(payload)
462464

463465
assert received.body_type == AmqpMessageBodyType.SEQUENCE
466+
# Confirm the decoded sequence contents round-trip, not just the body type.
467+
assert list(received.body) == [1, 2, 3]
464468

465469

466470
class TestServiceBusMessageBackcompat(AzureMgmtRecordedTestCase):

0 commit comments

Comments
 (0)