def test_build_occurs_1(): custom_type = xsd.Element( etree.QName("http://tests.python-zeep.org/", "authentication"), xsd.ComplexType( xsd.All([ xsd.Element( etree.QName("http://tests.python-zeep.org/", "item_1"), xsd.String(), ), xsd.Element( etree.QName("http://tests.python-zeep.org/", "item_2"), xsd.String(), ), ])), ) obj = custom_type(item_1="foo", item_2="bar") result = render_node(custom_type, obj) expected = load_xml(""" <document> <ns0:authentication xmlns:ns0="http://tests.python-zeep.org/"> <ns0:item_1>foo</ns0:item_1> <ns0:item_2>bar</ns0:item_2> </ns0:authentication> </document> """) assert_nodes_equal(result, expected) obj = custom_type.parse(result[0], None) assert obj.item_1 == "foo" assert obj.item_2 == "bar"
def test_build_pare_other_order(): custom_type = xsd.Element( etree.QName("http://tests.python-zeep.org/", "authentication"), xsd.ComplexType( xsd.All([ xsd.Element( etree.QName("http://tests.python-zeep.org/", "item_1"), xsd.String(), ), xsd.Element( etree.QName("http://tests.python-zeep.org/", "item_2"), xsd.String(), ), ])), ) xml = load_xml(""" <document> <ns0:authentication xmlns:ns0="http://tests.python-zeep.org/"> <ns0:item_2>bar</ns0:item_2> <ns0:item_1>foo</ns0:item_1> </ns0:authentication> </document> """) obj = custom_type.parse(xml[0], None) assert obj.item_1 == "foo" assert obj.item_2 == "bar"
def _resolve_body(self, info, definitions, parts): name = etree.QName(self.nsmap["soap-env"], "Body") if not info or not parts: return None # If the part name is omitted then all parts are available under # the soap:body tag. Otherwise only the part with the given name. if info["part"]: part_name = info["part"] sub_elements = [parts[part_name].element] else: sub_elements = [] for part_name, part in parts.items(): if part.element is not None: element = part.element.clone() element.attr_name = part_name or element.name else: element = xsd.Element(name=part_name, type_=part.type) sub_elements.append(element) if len(sub_elements) > 1: self._is_body_wrapped = True return xsd.Element(name, xsd.ComplexType(xsd.All(sub_elements))) else: self._is_body_wrapped = False return sub_elements[0]
def test_all_basic(): custom_type = xsd.Element( etree.QName('http://tests.python-zeep.org/', 'authentication'), xsd.ComplexType( xsd.All([ xsd.Element( etree.QName('http://tests.python-zeep.org/', 'item_1'), xsd.String()), xsd.Element( etree.QName('http://tests.python-zeep.org/', 'item_2'), xsd.String()), ]))) expected = etree.fromstring(""" <ns0:container xmlns:ns0="http://tests.python-zeep.org/"> <ns0:item_2>bar</ns0:item_2> <ns0:item_1>foo</ns0:item_1> </ns0:container> """) obj = custom_type.parse(expected, None) assert obj.item_1 == 'foo' assert obj.item_2 == 'bar'
def _resolve_body(self, info, definitions, parts): if not info: return xsd.Element(None, xsd.ComplexType([])) # If the part name is omitted then all parts are available under # the soap:body tag. Otherwise only the part with the given name. if info['part']: part_name = info['part'] sub_elements = [parts[part_name].element] else: sub_elements = [] for part_name, part in parts.items(): element = part.element.clone() element.attr_name = part_name or element.name sub_elements.append(element) if len(sub_elements) > 1: self._is_body_wrapped = True return xsd.Element(None, xsd.ComplexType(xsd.All(sub_elements))) else: self._is_body_wrapped = False return sub_elements[0]
def _resolve_header(self, info, definitions, parts): name = etree.QName(self.nsmap["soap-env"], "Header") container = xsd.All(consume_other=True) if not info: return xsd.Element(name, xsd.ComplexType(container)) for item in info: message_name = item["message"].text part_name = item["part"] message = definitions.get("messages", message_name) if message == self.abstract and part_name in parts: del parts[part_name] part = message.parts[part_name] if part.element: element = part.element.clone() element.attr_name = part_name else: element = xsd.Element(part_name, part.type) container.append(element) return xsd.Element(name, xsd.ComplexType(container))
def _resolve_header(self, info, definitions, parts): name = etree.QName(self.nsmap['soap-env'], 'Header') container = xsd.All() if not info: return xsd.Element(name, xsd.ComplexType(container)) for item in info: message_name = item['message'].text part_name = item['part'] message = definitions.get('messages', message_name) if message == self.abstract: del parts[part_name] part = message.parts[part_name] if part.element: element = part.element.clone() element.attr_name = part_name else: element = xsd.Element(part_name, part.type) container.append(element) return xsd.Element(name, xsd.ComplexType(container))