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_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_two_schemas(self): xml = utils.open_document('tests/assets/generation/multi_schema.wsdl') code = wsdl2py.generate_code_from_wsdl(xml, 'client') schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(2, [s for s in symbols if s.startswith('Schema_')]) assert_equals(['A'], list(schemas[0].elements)) assert_equals(['B'], list(schemas[1].elements))
def test_can_generate_code_for_two_schemas(self): xml = utils.open_document("tests/assets/generation/multi_schema.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(["A"], list(schemas[0].elements)) assert_equals(["B"], list(schemas[1].elements))
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 test_can_generate_list_enumeration(self): xml = utils.open_document('tests/assets/generation/enumeration.xsd') code = xsd2py.generate_code_from_xsd(xml) schemas, symbols = generated_symbols(code) assert_is_not_empty(schemas) assert_length(2, symbols) assert_true(issubclass(symbols['MyList'], xsd.List)) my_list = symbols['MyList']() assert_equals(my_list.accept(['B']), True)
def assert_is_soap_fault(self, response, fault_code=None, partial_fault_string=None): assert_equals(500, response.http_status_code) assert_equals('text/xml', response.http_headers['Content-Type']) fault_document = etree.fromstring(response.http_content) soap_envelope = fault_document.getroottree() namespaces = {'s': 'http://schemas.xmlsoap.org/soap/envelope/'} fault_nodes = soap_envelope.xpath('/s:Envelope/s:Body/s:Fault', namespaces=namespaces) assert_length(1, fault_nodes, message='expected exactly one SOAP fault') children = list(fault_nodes[0]) assert_length(2, children) xml_fault_code, fault_string = children if fault_code is None: fault_code = 'Client' assert_equals(fault_code, xml_fault_code.text) if partial_fault_string: assert_contains(partial_fault_string, fault_string.text)
def test_can_consume_generator_if_necessary(self): def generator(): for i in (1, 2, 3): yield i assert_length(3, generator()) generator_ = generator() assert_length(3, generator_) assert_length(0, generator_)
def test_passes_if_length_matches_actual(self): assert_length(0, []) assert_length(1, ['foo'])
def assert_fail(self, expected, actual, message=None): return assert_raises( AssertionError, lambda: assert_length(expected, actual, message=message))
def assert_fail(self, expected, actual, message=None): return assert_raises(AssertionError, lambda: assert_length(expected, actual, message=message))