Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix name of choice elements in sequence (fixes #1255) #1256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/zeep/xsd/elements/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def parse_xmlelements(self, xmlelements, schema, name=None, context=None):
for elm_name, element in self.elements:
try:
item_subresult = element.parse_xmlelements(
xmlelements, schema, name, context=context
xmlelements, schema, elm_name, context=context
)
except UnexpectedElementError:
if schema.settings.strict:
Expand Down
55 changes: 55 additions & 0 deletions tests/test_xsd_indicators_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,61 @@ def test_nested_choice():
assert result.b == "1"


def test_multiple_repeated_choice_in_sequence():
schema = xsd.Schema(
load_xml(
"""
<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://tests.python-zeep.org/"
targetNamespace="http://tests.python-zeep.org/"
elementFormDefault="qualified">
<element name="container">
<complexType>
<sequence>
<choice maxOccurs="2">
<element name="a" type="string"/>
<element name="b" type="string"/>
</choice>
<choice maxOccurs="2">
<element name="c" type="string"/>
<element name="d" type="string"/>
</choice>
</sequence>
</complexType>
</element>
<element name="a" type="string" />
<element name="b" type="string" />
</schema>
"""
)
)

schema.set_ns_prefix("tns", "http://tests.python-zeep.org/")
container_type = schema.get_element("tns:container")

item = container_type(_value_1=[{"a": "item-1"}], _value_2=[{"c": "item-2"}])
assert item._value_1[0] == {"a": "item-1"}
assert item._value_2[0] == {"c": "item-2"}

expected = load_xml(
"""
<document>
<ns0:container xmlns:ns0="http://tests.python-zeep.org/">
<ns0:a>item-1</ns0:a>
<ns0:c>item-2</ns0:c>
</ns0:container>
</document>
"""
)
node = render_node(container_type, item)
assert_nodes_equal(node, expected)

result = container_type.parse(expected[0], schema)
assert result._value_1[0] == {"a": "item-1"}
assert result._value_2[0] == {"c": "item-2"}


def test_unit_choice_parse_xmlelements_max_1():
schema = xsd.Schema(
load_xml(
Expand Down