def fault_to_parent(self, ctx, cls, inst, parent, name): PREF_SOAP_ENV = ctx.app.interface.prefmap[NS_SOAP11_ENV] tag_name = SOAP11_ENV("Fault") with parent.element(tag_name): parent.write( E("faultcode", '%s:%s' % (PREF_SOAP_ENV, inst.faultcode)), E("faultstring", inst.faultstring), E("faultactor", inst.faultactor), ) if isinstance(inst.detail, etree._Element): parent.write(E.detail(inst.detail)) # add other nonstandard fault subelements with get_members_etree self._write_members(ctx, cls, inst, parent)
def test_from_xml_w_detail(self): from lxml.etree import Element from lxml.etree import SubElement from spyne.const.xml import SOAP11_ENV element = Element(SOAP11_ENV('Fault')) fcode = SubElement(element, 'faultcode') fcode.text = 'soap11env:other' fstr = SubElement(element, 'faultstring') fstr.text = 'Testing' actor = SubElement(element, 'faultactor') actor.text = 'phreddy' detail = SubElement(element, 'detail') fault = XmlDocument().from_element(None, Fault, element) self.assertTrue(fault.detail is detail)
def schema_validation_error_to_parent(self, ctx, cls, inst, parent, **_): PREF_SOAP_ENV = ctx.app.interface.prefmap[NS_SOAP11_ENV] tag_name = SOAP11_ENV("Fault") with parent.element(tag_name): parent.write( E("faultcode", '%s:%s' % (PREF_SOAP_ENV, inst.faultcode)), # HACK: Does anyone know a better way of injecting raw xml entities? E("faultstring", html.fromstring(inst.faultstring).text), E("faultactor", inst.faultactor), ) if isinstance(inst.detail, etree._Element): parent.write(E.detail(inst.detail)) # add other nonstandard fault subelements with get_members_etree self._write_members(ctx, cls, inst, parent)
def test_from_xml_wo_detail(self): from lxml.etree import Element from lxml.etree import SubElement from spyne.const.xml import PREFMAP, SOAP11_ENV, NS_SOAP11_ENV soap_env = PREFMAP[NS_SOAP11_ENV] element = Element(SOAP11_ENV('Fault')) fcode = SubElement(element, 'faultcode') fcode.text = '%s:other' % soap_env fstr = SubElement(element, 'faultstring') fstr.text = 'Testing' actor = SubElement(element, 'faultactor') actor.text = 'phreddy' fault = XmlDocument().from_element(None, Fault, element) self.assertEqual(fault.faultcode, '%s:other' % soap_env) self.assertEqual(fault.faultstring, 'Testing') self.assertEqual(fault.faultactor, 'phreddy') self.assertEqual(fault.detail, None)