def test_implicit_target_namespace(self): xml = ('<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" \n' ' elementFormDefault="qualified">\n' ' <xs:element name="field" type="xsd:string" />\n' '</xs:schema>') xml_element = etree.fromstring(xml) generated_schema = xsdspec.Schema.parse_xmlelement(xml_element) xsd2py.schema_to_py(generated_schema, ['xs'], parent_namespace="http://site.example/ws/spec")
def test_can_generate_code_with_xsd_refs_to_elements_with_anoynmous_complex_types( self): # The final test should have an object graph representation of the # schema below. Currently I don't know how to represent multiple # xs:elements in a schema without using ComplexTypes. # Maybe we should have a special type like AnonymousComplexType and # put that directly into schema.elements? xml = utils.open_document( 'tests/assets/generation/reference_complex.xsd') schema = xsdspec.Schema.parse_xmlelement(etree.fromstring(xml)) code = xsd2py.schema_to_py(schema, ['xs']) schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(3, symbols) assert_contains('Person', symbols.keys()) assert_contains('Job', symbols.keys()) assert_equals(set(['person', 'job']), list(schemas[0].elements)) Job = symbols['Job'] Person = symbols['Person'] person_ref = Job.person assert_isinstance(person_ref, xsd.Ref) assert_equals(person_ref._type, Person) job = Job() person = Person() person.name = 'Foo' job.person = person
def test_can_generate_code_with_xsd_refs_to_elements_with_anoynmous_complex_types(self): # The final test should have an object graph representation of the # schema below. Currently I don't know how to represent multiple # xs:elements in a schema without using ComplexTypes. # Maybe we should have a special type like AnonymousComplexType and # put that directly into schema.elements? xml = utils.open_document('tests/assets/generation/reference_complex.xsd') schema = xsdspec.Schema.parse_xmlelement(etree.fromstring(xml)) code = xsd2py.schema_to_py(schema, ['xs']) schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(3, symbols) assert_contains('Person', symbols.keys()) assert_contains('Job', symbols.keys()) assert_equals(set(['person', 'job']), list(schemas[0].elements)) Job = symbols['Job'] Person = symbols['Person'] person_ref = Job.person assert_isinstance(person_ref, xsd.Ref) assert_equals(person_ref._type, Person) job = Job() person = Person() person.name = 'Foo' job.person = person
def test_can_generate_code_with_xsd_refs_to_elements_with_anoynmous_complex_types( self): raise SkipTest( 'References to elements with anonymous complex types are not yet implemented' ) # The final test should have an object graph representation of the # schema below. Currently I don't know how to represent multiple # xs:elements in a schema without using ComplexTypes. # Maybe we should have a special type like AnonymousComplexType and # put that directly into schema.elements? xml = ('<xs:schema targetNamespace="http://site.example/ws/spec" \n' ' xmlns:example="http://site.example/ws/spec" \n' ' xmlns:xs="http://www.w3.org/2001/XMLSchema" \n' ' elementFormDefault="qualified">\n' ' <xs:element name="person">\n' ' <xs:complexType>\n' ' <xs:sequence>\n' ' <xs:element name="name" type="xs:string" />\n' ' </xs:sequence>\n' ' </xs:complexType>\n' ' </xs:element>\n' ' <xs:element name="job">\n' ' <xs:complexType>\n' ' <xs:sequence>\n' ' <xs:element ref="example:person" />\n' ' </xs:sequence>\n' ' </xs:complexType>\n' ' </xs:element>\n' '</xs:schema>') xml_element = etree.fromstring(xml) generated_schema = xsdspec.Schema.parse_xmlelement(xml_element) code_string = xsd2py.schema_to_py(generated_schema, ['xs'], known_namespaces=[]) schema, new_symbols = self._generated_symbols(code_string) assert_not_none(schema) assert_length(3, new_symbols) assert_contains('Person', new_symbols.keys()) assert_contains('Job', new_symbols.keys()) assert_equals(set(['person', 'job']), list(schema.elements)) Job = new_symbols['Job'] Person = new_symbols['Person'] person_ref = Job.person assert_isinstance(person_ref, xsd.Ref) assert_equals(person_ref._type, Person) job = Job() person = Person() person.name = u'Foo' job.person = person
def test_can_generate_code_with_xsd_refs_to_elements_with_anoynmous_complex_types(self): raise SkipTest('References to elements with anonymous complex types are not yet implemented') # The final test should have an object graph representation of the # schema below. Currently I don't know how to represent multiple # xs:elements in a schema without using ComplexTypes. # Maybe we should have a special type like AnonymousComplexType and # put that directly into schema.elements? xml = ('<xs:schema targetNamespace="http://site.example/ws/spec" \n' ' xmlns:example="http://site.example/ws/spec" \n' ' xmlns:xs="http://www.w3.org/2001/XMLSchema" \n' ' elementFormDefault="qualified">\n' ' <xs:element name="person">\n' ' <xs:complexType>\n' ' <xs:sequence>\n' ' <xs:element name="name" type="xs:string" />\n' ' </xs:sequence>\n' ' </xs:complexType>\n' ' </xs:element>\n' ' <xs:element name="job">\n' ' <xs:complexType>\n' ' <xs:sequence>\n' ' <xs:element ref="example:person" />\n' ' </xs:sequence>\n' ' </xs:complexType>\n' ' </xs:element>\n' '</xs:schema>') xml_element = etree.fromstring(xml) generated_schema = xsdspec.Schema.parse_xmlelement(xml_element) code_string = xsd2py.schema_to_py(generated_schema, ['xs']) schema, new_symbols = generated_symbols(code_string) assert_not_none(schema) assert_length(3, new_symbols) assert_contains('Person', new_symbols.keys()) assert_contains('Job', new_symbols.keys()) assert_equals(set(['person', 'job']), list(schema.elements)) Job = new_symbols['Job'] Person = new_symbols['Person'] person_ref = Job.person assert_isinstance(person_ref, xsd.Ref) assert_equals(person_ref._type, Person) job = Job() person = Person() person.name = u'Foo' job.person = person
def test_implicit_target_namespace(self): xml = utils.open_document( 'tests/assets/generation/implicit_namespace.xsd') schema = xsdspec.Schema.parse_xmlelement(etree.fromstring(xml)) xsd2py.schema_to_py(schema, ['xs'], parent_namespace='http://site.example/ws/spec')
def test_implicit_target_namespace(self): xml = utils.open_document('tests/assets/generation/implicit_namespace.xsd') schema = xsdspec.Schema.parse_xmlelement(etree.fromstring(xml)) xsd2py.schema_to_py(schema, ['xs'], parent_namespace='http://site.example/ws/spec')