Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/python-addXmlTests-2026-2-30-16-25-8.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/http-client-python"
---

Add tests for XML storage
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import pytest
from payload.xml.aio import XmlClient
from payload.xml.models import (
Author,
Book,
SimpleModel,
ModelWithSimpleArrays,
ModelWithArrayOfModel,
Expand All @@ -21,6 +23,17 @@
ModelWithEncodedNames,
ModelWithEnum,
ModelWithDatetime,
ModelWithRenamedProperty,
ModelWithNestedModel,
ModelWithRenamedNestedModel,
ModelWithWrappedPrimitiveCustomItemNames,
ModelWithUnwrappedModelArray,
ModelWithRenamedWrappedModelArray,
ModelWithRenamedUnwrappedModelArray,
ModelWithRenamedWrappedAndItemModelArray,
ModelWithRenamedAttribute,
ModelWithNamespace,
ModelWithNamespaceOnProperties,
)


Expand Down Expand Up @@ -148,3 +161,104 @@ async def test_xml_error_value(client: XmlClient, core_library):
assert ex.value.status_code == 400
assert ex.value.model.message == "Something went wrong"
assert ex.value.model.code == 400


@pytest.mark.asyncio
async def test_model_with_renamed_property(client: XmlClient):
model = ModelWithRenamedProperty(title="foo", author="bar")
assert await client.model_with_renamed_property_value.get() == model
await client.model_with_renamed_property_value.put(model)


@pytest.mark.asyncio
async def test_model_with_nested_model(client: XmlClient):
model = ModelWithNestedModel(nested=SimpleModel(name="foo", age=123))
assert await client.model_with_nested_model_value.get() == model
await client.model_with_nested_model_value.put(model)


@pytest.mark.asyncio
async def test_model_with_renamed_nested_model(client: XmlClient):
model = ModelWithRenamedNestedModel(author=Author(name="foo"))
assert await client.model_with_renamed_nested_model_value.get() == model
await client.model_with_renamed_nested_model_value.put(model)


@pytest.mark.asyncio
async def test_model_with_wrapped_primitive_custom_item_names(client: XmlClient):
model = ModelWithWrappedPrimitiveCustomItemNames(tags=["fiction", "classic"])
assert await client.model_with_wrapped_primitive_custom_item_names_value.get() == model
await client.model_with_wrapped_primitive_custom_item_names_value.put(model)


@pytest.mark.skip(reason="XML unwrapped model array serialization not yet supported")
@pytest.mark.asyncio
async def test_model_with_unwrapped_model_array(client: XmlClient):
model = ModelWithUnwrappedModelArray(
items_property=[
SimpleModel(name="foo", age=123),
SimpleModel(name="bar", age=456),
]
)
assert await client.model_with_unwrapped_model_array_value.get() == model
await client.model_with_unwrapped_model_array_value.put(model)


@pytest.mark.asyncio
async def test_model_with_renamed_wrapped_model_array(client: XmlClient):
model = ModelWithRenamedWrappedModelArray(
items_property=[
SimpleModel(name="foo", age=123),
SimpleModel(name="bar", age=456),
]
)
assert await client.model_with_renamed_wrapped_model_array_value.get() == model
await client.model_with_renamed_wrapped_model_array_value.put(model)


@pytest.mark.skip(reason="XML unwrapped model array serialization not yet supported")
@pytest.mark.asyncio
async def test_model_with_renamed_unwrapped_model_array(client: XmlClient):
model = ModelWithRenamedUnwrappedModelArray(
items_property=[
SimpleModel(name="foo", age=123),
SimpleModel(name="bar", age=456),
]
)
assert await client.model_with_renamed_unwrapped_model_array_value.get() == model
await client.model_with_renamed_unwrapped_model_array_value.put(model)


@pytest.mark.asyncio
async def test_model_with_renamed_wrapped_and_item_model_array(client: XmlClient):
model = ModelWithRenamedWrappedAndItemModelArray(
books=[
Book(title="The Great Gatsby"),
Book(title="Les Miserables"),
]
)
assert await client.model_with_renamed_wrapped_and_item_model_array_value.get() == model
await client.model_with_renamed_wrapped_and_item_model_array_value.put(model)


@pytest.mark.asyncio
async def test_model_with_renamed_attribute(client: XmlClient):
model = ModelWithRenamedAttribute(id=123, title="The Great Gatsby", author="F. Scott Fitzgerald")
assert await client.model_with_renamed_attribute_value.get() == model
await client.model_with_renamed_attribute_value.put(model)


@pytest.mark.skip(reason="XML namespace serialization not yet supported")
@pytest.mark.asyncio
async def test_model_with_namespace(client: XmlClient):
model = ModelWithNamespace(id=123, title="The Great Gatsby")
assert await client.model_with_namespace_value.get() == model
await client.model_with_namespace_value.put(model)


@pytest.mark.skip(reason="XML namespace serialization not yet supported")
@pytest.mark.asyncio
async def test_model_with_namespace_on_properties(client: XmlClient):
model = ModelWithNamespaceOnProperties(id=123, title="The Great Gatsby", author="F. Scott Fitzgerald")
assert await client.model_with_namespace_on_properties_value.get() == model
await client.model_with_namespace_on_properties_value.put(model)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import pytest
from payload.xml import XmlClient
from payload.xml.models import (
Author,
Book,
SimpleModel,
ModelWithSimpleArrays,
ModelWithArrayOfModel,
Expand All @@ -21,6 +23,17 @@
ModelWithEncodedNames,
ModelWithEnum,
ModelWithDatetime,
ModelWithRenamedProperty,
ModelWithNestedModel,
ModelWithRenamedNestedModel,
ModelWithWrappedPrimitiveCustomItemNames,
ModelWithUnwrappedModelArray,
ModelWithRenamedWrappedModelArray,
ModelWithRenamedUnwrappedModelArray,
ModelWithRenamedWrappedAndItemModelArray,
ModelWithRenamedAttribute,
ModelWithNamespace,
ModelWithNamespaceOnProperties,
)


Expand Down Expand Up @@ -133,3 +146,93 @@ def test_xml_error_value(client: XmlClient, core_library):
assert ex.value.status_code == 400
assert ex.value.model.message == "Something went wrong"
assert ex.value.model.code == 400


def test_model_with_renamed_property(client: XmlClient):
model = ModelWithRenamedProperty(title="foo", author="bar")
assert client.model_with_renamed_property_value.get() == model
client.model_with_renamed_property_value.put(model)


def test_model_with_nested_model(client: XmlClient):
model = ModelWithNestedModel(nested=SimpleModel(name="foo", age=123))
assert client.model_with_nested_model_value.get() == model
client.model_with_nested_model_value.put(model)


def test_model_with_renamed_nested_model(client: XmlClient):
model = ModelWithRenamedNestedModel(author=Author(name="foo"))
assert client.model_with_renamed_nested_model_value.get() == model
client.model_with_renamed_nested_model_value.put(model)


def test_model_with_wrapped_primitive_custom_item_names(client: XmlClient):
model = ModelWithWrappedPrimitiveCustomItemNames(tags=["fiction", "classic"])
assert client.model_with_wrapped_primitive_custom_item_names_value.get() == model
client.model_with_wrapped_primitive_custom_item_names_value.put(model)


@pytest.mark.skip(reason="XML unwrapped model array serialization not yet supported")
def test_model_with_unwrapped_model_array(client: XmlClient):
model = ModelWithUnwrappedModelArray(
items_property=[
SimpleModel(name="foo", age=123),
SimpleModel(name="bar", age=456),
]
)
assert client.model_with_unwrapped_model_array_value.get() == model
client.model_with_unwrapped_model_array_value.put(model)


def test_model_with_renamed_wrapped_model_array(client: XmlClient):
model = ModelWithRenamedWrappedModelArray(
items_property=[
SimpleModel(name="foo", age=123),
SimpleModel(name="bar", age=456),
]
)
assert client.model_with_renamed_wrapped_model_array_value.get() == model
client.model_with_renamed_wrapped_model_array_value.put(model)


@pytest.mark.skip(reason="XML unwrapped model array serialization not yet supported")
def test_model_with_renamed_unwrapped_model_array(client: XmlClient):
model = ModelWithRenamedUnwrappedModelArray(
items_property=[
SimpleModel(name="foo", age=123),
SimpleModel(name="bar", age=456),
]
)
assert client.model_with_renamed_unwrapped_model_array_value.get() == model
client.model_with_renamed_unwrapped_model_array_value.put(model)


def test_model_with_renamed_wrapped_and_item_model_array(client: XmlClient):
model = ModelWithRenamedWrappedAndItemModelArray(
books=[
Book(title="The Great Gatsby"),
Book(title="Les Miserables"),
]
)
assert client.model_with_renamed_wrapped_and_item_model_array_value.get() == model
client.model_with_renamed_wrapped_and_item_model_array_value.put(model)


def test_model_with_renamed_attribute(client: XmlClient):
model = ModelWithRenamedAttribute(id=123, title="The Great Gatsby", author="F. Scott Fitzgerald")
assert client.model_with_renamed_attribute_value.get() == model
client.model_with_renamed_attribute_value.put(model)


@pytest.mark.skip(reason="XML namespace serialization not yet supported")
def test_model_with_namespace(client: XmlClient):
model = ModelWithNamespace(id=123, title="The Great Gatsby")
assert client.model_with_namespace_value.get() == model
client.model_with_namespace_value.put(model)


@pytest.mark.skip(reason="XML namespace serialization not yet supported")
def test_model_with_namespace_on_properties(client: XmlClient):
model = ModelWithNamespaceOnProperties(id=123, title="The Great Gatsby", author="F. Scott Fitzgerald")
assert client.model_with_namespace_on_properties_value.get() == model
client.model_with_namespace_on_properties_value.put(model)
Loading