Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/http-client-python"
---

Add test cases for XML model with enum and datetime properties (tests will activate when PR #9660 is merged)
Original file line number Diff line number Diff line change
Expand Up @@ -1020,11 +1020,15 @@ def _deserialize_with_callable(
return float(value.text) if value.text else None
if deserializer is bool:
return value.text == "true" if value.text else None
if deserializer in _DESERIALIZE_MAPPING.values() or deserializer in _DESERIALIZE_MAPPING_WITHFORMAT.values():
return typing.cast(typing.Callable[[typing.Any], typing.Any], deserializer)(value.text) if value.text else None
if deserializer is None:
return value
if deserializer in [int, float, bool]:
return deserializer(value)
if isinstance(deserializer, CaseInsensitiveEnumMeta):
if isinstance(value, ET.Element):
value = value.text if value.text else None
try:
return deserializer(value)
except ValueError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import datetime

import pytest
from payload.xml.aio import XmlClient
from payload.xml.models import (
Expand All @@ -18,6 +20,9 @@
ModelWithText,
ModelWithDictionary,
ModelWithEncodedNames,
ModelWithEnum,
ModelWithDatetime,
Status,
)


Expand Down Expand Up @@ -119,6 +124,23 @@ async def test_model_with_encoded_names(client: XmlClient):
await client.model_with_encoded_names_value.put(model)


@pytest.mark.asyncio
async def test_model_with_enum(client: XmlClient):
model = ModelWithEnum(status=Status.SUCCESS)
assert await client.model_with_enum_value.get() == model
await client.model_with_enum_value.put(model)


@pytest.mark.asyncio
async def test_model_with_datetime(client: XmlClient):
model = ModelWithDatetime(
rfc3339=datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc),
rfc7231=datetime.datetime(2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc),
)
assert await client.model_with_datetime_value.get() == model
await client.model_with_datetime_value.put(model)


@pytest.mark.asyncio
async def test_xml_error_value(client: XmlClient, core_library):
with pytest.raises(core_library.exceptions.HttpResponseError) as ex:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for
# license information.
# --------------------------------------------------------------------------
import datetime

import pytest
from payload.xml import XmlClient
from payload.xml.models import (
Expand All @@ -18,6 +20,9 @@
ModelWithText,
ModelWithDictionary,
ModelWithEncodedNames,
ModelWithEnum,
ModelWithDatetime,
Status,
)


Expand Down Expand Up @@ -107,6 +112,21 @@ def test_model_with_encoded_names(client: XmlClient):
client.model_with_encoded_names_value.put(model)


def test_model_with_enum(client: XmlClient):
model = ModelWithEnum(status=Status.SUCCESS)
assert client.model_with_enum_value.get() == model
client.model_with_enum_value.put(model)


def test_model_with_datetime(client: XmlClient):
model = ModelWithDatetime(
rfc3339=datetime.datetime(2022, 8, 26, 18, 38, 0, tzinfo=datetime.timezone.utc),
rfc7231=datetime.datetime(2022, 8, 26, 14, 38, 0, tzinfo=datetime.timezone.utc),
)
assert client.model_with_datetime_value.get() == model
client.model_with_datetime_value.put(model)


def test_xml_error_value(client: XmlClient, core_library):
with pytest.raises(core_library.exceptions.HttpResponseError) as ex:
client.xml_error_value.get()
Expand Down
Loading
Loading