[http-client-python] Add XML deserialization tests for EnumerationResults payload#9778
[http-client-python] Add XML deserialization tests for EnumerationResults payload#9778
Conversation
…nResults payload Co-authored-by: l0lawrence <100643745+l0lawrence@users.noreply.github.com>
commit: |
|
|
||
| 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>' |
There was a problem hiding this comment.
@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
There was a problem hiding this comment.
@copilot like if our enumerationResults model followed this model pattern -- https://github.com/l0lawrence/azure-sdk-for-python/blob/14028a4655c9055e234fb142a91da64fdd0b82f4/sdk/storage/azure-storage-blob/azure/storage/blob/_generated/models/_models_py3.py#L1566
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
| ) | ||
| 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"}) |
There was a problem hiding this comment.
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 |
Adds unit test coverage for deserializing a blob storage-style
EnumerationResultsXML 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
TestXmlDeserialization::test_enumeration_results— baseline test with the original payload:TestXmlDeserialization::test_enumeration_results_nested_empty_list—Blobsis a nestedBlobsSegmentmodel with ablob_prefixes: list[BlobPrefix]field (usingitemsNamewrapper), and the XML has<Blobs><BlobPrefixes /></Blobs>:# result.blobs.blob_prefixes == []TestXmlDeserialization::test_enumeration_results_azure_sdk_pattern— follows the real Azure Blob Storage SDK model pattern whereBlobsSegmenthas two unwrapped list fields (blob_prefixesandblob_items) mirroringBlobHierarchyListSegment. With<Blobs />, no matching children exist so both lists areNone:TestXmlDeserialization::test_enumeration_results_blobs_unwrapped— documents the behavior when a model-typed field is annotated withunwrapped=True: the deserialization enters the unwrapped-list branch and stores the collectedET.Elementobjects as-is, returning alist[ET.Element]instead of the expected model instance.Original prompt
🔒 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.