@@ -95,6 +95,84 @@ def test_choice_element_second_elm():
9595 assert value .item_2 == 'foo'
9696 assert value .item_3 is None
9797
98+ def test_choice_element_second_elm_positional ():
99+ node = etree .fromstring ("""
100+ <?xml version="1.0"?>
101+ <xsd:schema
102+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
103+ xmlns:tns="http://tests.python-zeep.org/"
104+ elementFormDefault="qualified"
105+ targetNamespace="http://tests.python-zeep.org/">
106+ <xsd:complexType name="type_1">
107+ <xsd:sequence>
108+ <xsd:element name="child_1" type="xsd:string"/>
109+ <xsd:element name="child_2" type="xsd:string"/>
110+ </xsd:sequence>
111+ </xsd:complexType>
112+ <xsd:complexType name="type_2">
113+ <xsd:sequence>
114+ <xsd:element name="child_1" type="xsd:string"/>
115+ <xsd:element name="child_2" type="xsd:string"/>
116+ </xsd:sequence>
117+ </xsd:complexType>
118+ <xsd:element name="container">
119+ <xsd:complexType>
120+ <xsd:choice>
121+ <xsd:element name="item_1" type="tns:type_1" />
122+ <xsd:element name="item_2" type="tns:type_2" />
123+ </xsd:choice>
124+ </xsd:complexType>
125+ </xsd:element>
126+ <xsd:element name="containerArray">
127+ <xsd:complexType>
128+ <xsd:sequence>
129+ <xsd:choice>
130+ <xsd:element name="item_1" type="tns:type_1" />
131+ <xsd:element name="item_2" type="tns:type_2" />
132+ </xsd:choice>
133+ </xsd:sequence>
134+ </xsd:complexType>
135+ </xsd:element>
136+ </xsd:schema>
137+ """ .strip ())
138+ schema = xsd .Schema (node )
139+
140+ child = schema .get_type ('ns0:type_2' )(child_1 = 'ha' , child_2 = 'ho' )
141+
142+ element = schema .get_element ('ns0:container' )
143+ with pytest .raises (TypeError ):
144+ value = element (child )
145+ value = element (item_2 = child )
146+
147+ element = schema .get_element ('ns0:containerArray' )
148+ with pytest .raises (TypeError ):
149+ value = element (child )
150+ value = element (item_2 = child )
151+
152+ element = schema .get_element ('ns0:container' )
153+ value = element (item_2 = child )
154+ assert value .item_1 is None
155+ assert value .item_2 == child
156+
157+ expected = """
158+ <document>
159+ <ns0:container xmlns:ns0="http://tests.python-zeep.org/">
160+ <ns0:item_2>
161+ <ns0:child_1>ha</ns0:child_1>
162+ <ns0:child_2>ho</ns0:child_2>
163+ </ns0:item_2>
164+ </ns0:container>
165+ </document>
166+ """
167+ node = etree .Element ('document' )
168+ element .render (node , value )
169+ assert_nodes_equal (expected , node )
170+
171+ value = element .parse (node [0 ], schema )
172+ assert value .item_1 is None
173+ assert value .item_2 .child_1 == 'ha'
174+ assert value .item_2 .child_2 == 'ho'
175+
98176
99177def test_choice_element_multiple ():
100178 node = etree .fromstring ("""
0 commit comments