def test_can_generate_code_with_xsd_refs_to_simple_elements(self): xml = utils.open_document( 'tests/assets/generation/reference_simple.xsd') code = xsd2py.generate_code_from_xsd(xml) schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) # somehow we need to be able to have schemas with multiple possible # root elements assert_length(3, symbols) assert_contains('Name', symbols.keys()) assert_contains('Job', symbols.keys()) assert_equals(set(['name', 'job']), list(schemas[0].elements)) Job = symbols['Job'] Name = symbols['Name'] name_ref = Job.name # not sure if these assertions are correct but they should give you # the idea assert_isinstance(name_ref, xsd.Ref) assert_equals(name_ref._type, Name) job = Job() # Should not raise job.name = u'Foo'
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_simple_elements(self): xml = utils.open_document('tests/assets/generation/reference_simple.xsd') code = xsd2py.generate_code_from_xsd(xml) schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) # somehow we need to be able to have schemas with multiple possible # root elements assert_length(3, symbols) assert_contains('Name', symbols.keys()) assert_contains('Job', symbols.keys()) assert_equals(set(['name', 'job']), list(schemas[0].elements)) Job = symbols['Job'] Name = symbols['Name'] name_ref = Job.name # not sure if these assertions are correct but they should give you # the idea assert_isinstance(name_ref, xsd.Ref) assert_equals(name_ref._type, Name) job = Job() # Should not raise job.name = u'Foo'
def test_can_generate_code_for_inheritance(self): xml = utils.open_document('tests/assets/generation/inheritance.wsdl') code = wsdl2py.generate_code_from_wsdl(xml, 'client') schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(4, symbols) assert_equals(['B', 'A'], list(schemas[0].elements)) assert_isinstance(schemas[0].elements['B']._type, xsd.String) assert_isinstance(schemas[0].elements['A']._type, schemas[0].elements['B']._type.__class__)
def test_can_generate_code_for_simple_element(self): xml = utils.open_document('tests/assets/generation/simple_element.xsd') code = xsd2py.generate_code_from_xsd(xml) schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(1, symbols) assert_equals(['simpleElement'], list(schemas[0].elements)) simple_element = schemas[0].elements['simpleElement'] assert_isinstance(simple_element._type, xsd.String)
def assert_fail(self, value, klass, message=None): return assert_raises( AssertionError, lambda: assert_isinstance(value, klass, message=message))
def test_passes_if_object_is_instance_of_class(self): assert_isinstance({}, dict) assert_isinstance('', basestring)
def assert_fail(self, value, klass, message=None): return assert_raises(AssertionError, lambda: assert_isinstance(value, klass, message=message))