def test_add_to_schema_no_extends(self): from spyne.const.xml import XSD class cls(Fault): __namespace__='ns' @classmethod def get_type_name_ns(self, app): return 'testing:My' interface = Interface(FakeApp()) interface.add_class(cls) pref = cls.get_namespace_prefix(interface) wsdl = Wsdl11(interface) wsdl.build_interface_document('prot://addr') schema = wsdl.get_schema_info(pref) self.assertEqual(len(schema.types), 1) c_cls = interface.classes['{ns}cls'] c_elt = schema.types[0] self.assertTrue(c_cls is cls) self.assertEqual(c_elt.tag, XSD('complexType')) self.assertEqual(c_elt.get('name'), 'cls') self.assertEqual(len(schema.elements), 1) e_elt = schema.elements.values()[0] self.assertEqual(e_elt.tag, XSD('element')) self.assertEqual(e_elt.get('name'), 'cls') self.assertEqual(e_elt.get('type'), 'testing:My') self.assertEqual(len(e_elt), 0)
def test_add_to_schema_w_extends(self): import spyne.const.xml_ns ns_xsd = spyne.const.xml_ns.xsd class base(Fault): __namespace__ = 'ns' @classmethod def get_type_name_ns(self, app): return 'testing:Base' class cls(Fault): __namespace__ = 'ns' @classmethod def get_type_name_ns(self, app): return 'testing:My' interface = Interface(FakeApp()) interface.add_class(cls) pref = cls.get_namespace_prefix(interface) wsdl = Wsdl11(interface) wsdl.build_interface_document('prot://addr') schema = wsdl.get_schema_info(pref) self.assertEqual(len(schema.types), 1) self.assertEqual(len(interface.classes), 1) c_cls = interface.classes.values()[0] c_elt = schema.types.values()[0] print(c_cls, cls) self.failUnless(c_cls is cls) self.assertEqual(c_elt.tag, '{%s}complexType' % ns_xsd) self.assertEqual(c_elt.get('name'), 'Fault') self.assertEqual(len(c_elt), 0)
def test_add_to_schema(self): class CM(ComplexModel): i = Integer s = String a = XmlAttribute(String) app = FakeApp() app.tns = 'tns' CM.resolve_namespace(CM, app.tns) interface = Interface(app) interface.add_class(CM) wsdl = Wsdl11(interface) wsdl.build_interface_document('http://a-aaaa.com') pref = CM.get_namespace_prefix(interface) type_def = wsdl.get_schema_info(pref).types[CM.get_type_name()] attribute_def = type_def.find('{%s}attribute' % xml_ns.xsd) print(etree.tostring(type_def, pretty_print=True)) self.assertIsNotNone(attribute_def) self.assertEqual(attribute_def.get('name'), 'a') self.assertEqual(attribute_def.get('type'), CM.a.type.get_type_name_ns(interface))
def test_add_to_schema_w_extends(self): from spyne.const.xml import XSD class base(Fault): __namespace__ = 'ns' @classmethod def get_type_name_ns(self, app): return 'testing:Base' class cls(Fault): __namespace__ = 'ns' @classmethod def get_type_name_ns(self, app): return 'testing:My' interface = Interface(FakeApp()) interface.add_class(cls) pref = cls.get_namespace_prefix(interface) wsdl = Wsdl11(interface) wsdl.build_interface_document('prot://addr') schema = wsdl.get_schema_info(pref) self.assertEqual(len(schema.types), 1) self.assertEqual(len(interface.classes), 1) c_cls = next(iter(interface.classes.values())) c_elt = next(iter(schema.types.values())) self.failUnless(c_cls is cls) self.assertEqual(c_elt.tag, XSD('complexType')) self.assertEqual(c_elt.get('name'), 'cls') from lxml import etree print(etree.tostring(c_elt, pretty_print=True)) self.assertEqual(len(c_elt), 0)