Skip to content

Comments

[http-client-python] Add XML deserialization tests for EnumerationResults payload#9778

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-xml-deserialization-test
Draft

[http-client-python] Add XML deserialization tests for EnumerationResults payload#9778
Copilot wants to merge 4 commits intomainfrom
copilot/add-xml-deserialization-test

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

Adds unit test coverage for deserializing a blob storage-style EnumerationResults XML payload, which exercises several deserialization edge cases in combination: root-element attributes, non-empty text elements, an empty element mapped to a list type, an empty element mapped to a string type, nested empty lists within a container model, and the Azure SDK unwrapped-list pattern.

Changes

  • New test TestXmlDeserialization::test_enumeration_results — baseline test with the original payload:
xml_payload = '<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://service.blob.core.windows.net/" ContainerName="acontainer108f32e8"><Delimiter>/</Delimiter><Blobs /><NextMarker /></EnumerationResults>'
# result.blobs       == []   # <Blobs /> → empty list
# result.next_marker == ""   # <NextMarker /> → empty string
  • New test TestXmlDeserialization::test_enumeration_results_nested_empty_listBlobs is a nested BlobsSegment model with a blob_prefixes: list[BlobPrefix] field (using itemsName wrapper), and the XML has <Blobs><BlobPrefixes /></Blobs>:
# result.blobs.blob_prefixes == []
  • New test TestXmlDeserialization::test_enumeration_results_azure_sdk_pattern — follows the real Azure Blob Storage SDK model pattern where BlobsSegment has two unwrapped list fields (blob_prefixes and blob_items) mirroring BlobHierarchyListSegment. With <Blobs />, no matching children exist so both lists are None:
# result.blobs.blob_prefixes is None   # unwrapped empty list → None
# result.blobs.blob_items    is None   # unwrapped empty list → None
  • New test TestXmlDeserialization::test_enumeration_results_blobs_unwrapped — documents the behavior when a model-typed field is annotated with unwrapped=True: the deserialization enters the unwrapped-list branch and stores the collected ET.Element objects as-is, returning a list[ET.Element] instead of the expected model instance.
Original prompt

This section details on the original issue you should resolve

<issue_title>[http-client-python] model base deserialization</issue_title>
<issue_description>Can we add a new test for deserializing the following xml payload:

<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://service.blob.core.windows.net/" ContainerName="acontainer108f32e8"><Delimiter>/</Delimiter><Blobs /><NextMarker /></EnumerationResults></issue_description>

<agent_instructions>to the http-client-python package</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…nResults payload

Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Feb 23, 2026
Copilot AI changed the title [WIP] Add test for xml payload deserialization [http-client-python] Add XML deserialization test for EnumerationResults payload Feb 23, 2026
Copilot AI requested a review from l0lawrence February 23, 2026 22:35
@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 24, 2026

Open in StackBlitz

npm i https://pkg.pr.new/microsoft/typespec/@typespec/http@9778
npm i https://pkg.pr.new/microsoft/typespec/@typespec/http-client@9778

commit: bd1f951


def test_enumeration_results(self):
"""Test deserializing an Azure Blob Storage EnumerationResults XML payload."""
xml_payload = '<?xml version="1.0" encoding="utf-8"?><EnumerationResults ServiceEndpoint="https://service.blob.core.windows.net/" ContainerName="acontainer108f32e8"><Delimiter>/</Delimiter><Blobs /><NextMarker /></EnumerationResults>'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot what if the model we are deserializing could potential have a list of lists and both are empty, like blobs contains blobprefixes which expects an empty list

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_enumeration_results_nested_empty_list in commit 833e54e. It uses XML <Blobs><BlobPrefixes /></Blobs> where blobs is a BlobsSegment model containing blob_prefixes: list[BlobPrefix]. The test asserts that result.blobs.blob_prefixes == [] — an empty <BlobPrefixes /> element inside a container correctly deserializes to an empty list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_enumeration_results_azure_sdk_pattern in commit 8caa873. It follows the linked Azure SDK model — BlobsSegment has both blob_prefixes: list[BlobPrefix] (unwrapped) and blob_items: list[BlobItem] (unwrapped). With <Blobs />, no matching children are found so both lists are None.

…est for EnumerationResults

Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
Copilot AI changed the title [http-client-python] Add XML deserialization test for EnumerationResults payload [http-client-python] Add XML deserialization tests for EnumerationResults payload Feb 24, 2026
)
container_name: str = rest_field(name="ContainerName", xml={"name": "ContainerName", "attribute": True})
delimiter: str = rest_field(name="Delimiter", xml={"name": "Delimiter"})
blobs: BlobsSegment = rest_field(name="Blobs", xml={"name": "Blobs"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot what if blobs is xml.unwrapped True

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test_enumeration_results_blobs_unwrapped in commit 8caa873. When a model-typed field (blobs: BlobsSegment) has unwrapped=True, the deserialization enters the unwrapped-list branch and stores the collected XML elements as-is — result.blobs becomes a list[ET.Element] instead of a BlobsSegment instance. The test documents this current behavior.

…ML deserialization tests

Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
assert result.delimiter == "/"
assert isinstance(result.blobs, BlobsSegment)
# With <Blobs />, no <BlobPrefix> or <Blob> children exist → unwrapped empty lists stay None
assert result.blobs.blob_prefixes is None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want this to be None?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[http-client-python] model base deserialization

2 participants