def test_can_parse_references(self): 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>') schema = xsdspec.Schema.parsexml(xml) job_element = schema.elements[1] assert_equals('job', job_element.name) person_reference = job_element.complexType.sequence.elements[0] assert_none(person_reference.name) assert_equals('example:person', person_reference.ref) person_element = schema.elements[0] assert_equals('person', person_element.name)
def test_can_parse_references(self): 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>' ) schema = xsdspec.Schema.parsexml(xml) job_element = schema.elements[1] assert_equals('job', job_element.name) person_reference = job_element.complexType.sequence.elements[0] assert_none(person_reference.name) assert_equals('example:person', person_reference.ref) person_element = schema.elements[0] assert_equals('person', person_element.name)
def test_can_omit_optional_attributes(self): instance = self.SampleType(name='someName') element = etree.Element('sample') instance.render(element, instance) assert_equals('someName', element.get('name')) assert_none(element.get('value')) assert_none(element.get('type'))
def test_can_omit_optional_attributes(self): with testutil.import_code(self.code) as generated: instance = generated.SampleType(sampleAttrs=generated.SampleAttrs(name='someName')) element = etree.Element('sample') instance.render(element, instance) assert_equals('someName', element.get('name')) assert_none(element.get('value')) assert_none(element.get('type'))
def test_can_lookup_element_by_name(self): ns = 'http://soap.example/schema.xsd' class CodeType(xsd.String): pattern = r'[0-9]{5}' schema = xsd.Schema(ns, location=ns, elementFormDefault=xsd.ElementFormDefault.QUALIFIED, simpleTypes=[CodeType], elements={'code': xsd.Element(CodeType)} ) schema_element = schema.get_element_by_name('code') assert_equals(CodeType, schema_element._passed_type) assert_none(schema.get_element_by_name('invalid'))
def test_can_parse_choice_groups(self): schema = self._choice_schema() Result = schema.elements['result']._type xml = '<message>foo bar</message>' self.assert_is_valid(self._result_wrap(xml), schema) result = Result.parse_xmlelement(etree.fromstring(xml)) assert_equals('foo bar', result.message) assert_none(result.code) xml = '<code>123</code>' self.assert_is_valid(self._result_wrap(xml), schema) result = Result.parse_xmlelement(etree.fromstring(xml)) assert_none(result.message) assert_equals('123', result.code)
def test_soap11_fault_handling(self): service = soap.Service( location='mock_location', methods=[], name=None, schemas=[], targetNamespace=None, version=soap.SOAPVersion.SOAP11, ) stub = soap.Stub(location='empty', service=service) e = assert_raises(core.SOAPError, lambda: stub._handle_response(None, None, SOAP11_ERROR_MESSAGE)) assert_equals('Result', e.code) assert_none(e.message) assert_equals('Resultset empty2.', e.actor)
def test_can_lookup_element_by_name(self): ns = 'http://soap.example/schema.xsd' class CodeType(xsd.String): pattern = r'[0-9]{5}' schema = xsd.Schema( ns, location=ns, elementFormDefault=xsd.ElementFormDefault.QUALIFIED, simpleTypes=[CodeType], elements={'code': xsd.Element(CodeType)}) schema_element = schema.get_element_by_name('code') assert_equals(CodeType, schema_element._passed_type) assert_none(schema.get_element_by_name('invalid'))
def test_soap11_fault_handling(self): service = soap.Service( location='mock_location', methods=[], name=None, schemas=[], targetNamespace=None, version=soap.SOAPVersion.SOAP11, ) stub = soap.Stub(location='empty', service=service) e = assert_raises( core.SOAPError, lambda: stub._handle_response(None, None, SOAP11_ERROR_MESSAGE)) assert_equals('Result', e.code) assert_none(e.message) assert_equals('Resultset empty2.', e.actor)
def assert_fail(self, value, message=None): return assert_raises(AssertionError, lambda: assert_none(value, message=message))
def test_soap11_noactor_parsing(self): envelope = soap11.Envelope.parsexml(SOAP11_ERROR_MESSAGE_NO_ACTOR) code, message, actor = soap11.parse_fault_message(envelope.Body.Fault) assert_equals('Result', code) assert_equals('String', message) assert_none(actor)
def test_soap11_actor_parsing(self): envelope = soap11.Envelope.parsexml(SOAP11_ERROR_MESSAGE) code, message, actor = soap11.parse_fault_message(envelope.Body.Fault) assert_equals('Result', code) assert_none(message) assert_equals('Resultset empty2.', actor)
def test_soap12_noactor_parsing(self): envelope = soap12.Envelope.parsexml(SOAP12_ERROR_NOROLE) code, message, actor = soap12.parse_fault_message(envelope.Body.Fault) assert_equals('env:Sender', code) assert_equals('\nMessage does not have necessary info\n', message) assert_none(actor)
def test_can_enforce_timezone_aware_checks(self): datetime = DateTime.now() assert_none(datetime.tzinfo) assert_almost_now(datetime) self.assert_fail(datetime, tz=UTC)
def test_passes_if_value_is_none(self): assert_none(None)