def test_xml_encoding(self, capsys): """Test that the encoding listed in the XML declaration is honored.""" xml_format = u('<?xml version="1.0" encoding="%s"?><a>\u00D8</a>') data1 = (xml_format % ("UTF-8", )).encode('utf-8') data2 = (xml_format % ("latin1", )).encode('latin1') CompareSAX.data2data(data1, data2) assert_no_output(capsys)
def test_xml_encoding(self, capsys): """Test that the encoding listed in the XML declaration is honored.""" xml_format = u('<?xml version="1.0" encoding="%s"?><a>\u00D8</a>') data1 = (xml_format % ("UTF-8",)).encode('utf-8') data2 = (xml_format % ("latin1",)).encode('latin1') CompareSAX.data2data(data1, data2) assert_no_output(capsys)
def test_translation(monkeypatch): """Python <--> XML representation translation on marshall/unmarshall.""" anObject = _Dummy() class MockType(XBuiltin): def __init__(self, *args, **kwargs): self._mock_translate_log = [] super(MockType, self).__init__(*args, **kwargs) def translate(self, value, topython=True): self._mock_translate_log.append((value, topython)) if topython: return anObject return "'ollywood" _monkeypatch_builtin_XSD_type_registry(monkeypatch) Factory.maptag("woof", MockType) namespace = "I'm a little tea pot, short and stout..." wsdl = testutils.wsdl("""\ <xsd:element name="wi" type="xsd:woof"/> <xsd:element name="wo" type="xsd:woof"/>""", input="wi", output="wo", xsd_target_namespace=namespace, operation_name="f") client = testutils.client_from_wsdl(wsdl, nosend=True, prettyxml=True) # Check suds library's XSD schema input parameter information. schema = client.wsdl.schema element_in = schema.elements["wi", namespace] assert element_in.name == "wi" element_out = schema.elements["wo", namespace] assert element_out.name == "wo" schema_object_in = element_in.resolve() schema_object_out = element_out.resolve() assert element_in is client.sd[0].params[0][0] assert schema_object_in is client.sd[0].params[0][1] assert schema_object_in.__class__ is MockType assert schema_object_in._mock_translate_log == [] assert schema_object_out.__class__ is MockType assert schema_object_out._mock_translate_log == [] # Construct operation invocation request - test marshalling. request = client.service.f(55) assert schema_object_in._mock_translate_log == [(55, False)] assert schema_object_out._mock_translate_log == [] CompareSAX.data2data(request.envelope, """\ <?xml version="1.0" encoding="UTF-8"?> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Header/> <Body> <wi xmlns="%s">'ollywood</wi> </Body> </Envelope>""" % (namespace,)) # Process operation response - test unmarshalling. response = client.service.f(__inject=dict(reply=suds.byte_str("""\ <?xml version="1.0"?> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <wo xmlns="%s">fri-fru</wo> </Body> </Envelope>""" % (namespace,)))) assert response is anObject assert schema_object_in._mock_translate_log == [(55, False)] assert schema_object_out._mock_translate_log == [("fri-fru", True)]
def _assert_request_content(request, expected_xml): CompareSAX.data2data(request.envelope, expected_xml)
def _assert_request_content(request, expected_xml): CompareSAX.data2data(request.envelope, expected_xml)
def test_translation(monkeypatch): """Python <--> XML representation translation on marshall/unmarshall.""" anObject = _Dummy() class MockType(XBuiltin): def __init__(self, *args, **kwargs): self._mock_translate_log = [] super(MockType, self).__init__(*args, **kwargs) def translate(self, value, topython=True): self._mock_translate_log.append((value, topython)) if topython: return anObject return "'ollywood" _monkeypatch_builtin_XSD_type_registry(monkeypatch) Factory.maptag("woof", MockType) namespace = "I'm a little tea pot, short and stout..." wsdl = testutils.wsdl("""\ <xsd:element name="wi" type="xsd:woof"/> <xsd:element name="wo" type="xsd:woof"/>""", input="wi", output="wo", xsd_target_namespace=namespace, operation_name="f") client = testutils.client_from_wsdl(wsdl, nosend=True, prettyxml=True) # Check suds library's XSD schema input parameter information. schema = client.wsdl.schema element_in = schema.elements["wi", namespace] assert element_in.name == "wi" element_out = schema.elements["wo", namespace] assert element_out.name == "wo" schema_object_in = element_in.resolve() schema_object_out = element_out.resolve() assert element_in is client.sd[0].params[0][0] assert schema_object_in is client.sd[0].params[0][1] assert schema_object_in.__class__ is MockType assert schema_object_in._mock_translate_log == [] assert schema_object_out.__class__ is MockType assert schema_object_out._mock_translate_log == [] # Construct operation invocation request - test marshalling. request = client.service.f(55) assert schema_object_in._mock_translate_log == [(55, False)] assert schema_object_out._mock_translate_log == [] CompareSAX.data2data( request.envelope, """\ <?xml version="1.0" encoding="UTF-8"?> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Header/> <Body> <wi xmlns="%s">'ollywood</wi> </Body> </Envelope>""" % (namespace, )) # Process operation response - test unmarshalling. response = client.service.f(__inject=dict(reply=suds.byte_str("""\ <?xml version="1.0"?> <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"> <Body> <wo xmlns="%s">fri-fru</wo> </Body> </Envelope>""" % (namespace, )))) assert response is anObject assert schema_object_in._mock_translate_log == [(55, False)] assert schema_object_out._mock_translate_log == [("fri-fru", True)]
def test_string_input_types(self, type1, type2, capsys): xml = "<a/>" CompareSAX.data2data(type1(xml), type2(xml)) assert_no_output(capsys)
def test_data2data(self, data1, data2, capsys): CompareSAX.data2data(data1, data2) assert_no_output(capsys)
def test_empty_document(self, capsys): a = suds.sax.document.Document() b = suds.sax.document.Document() CompareSAX.document2document(a, b) assert_no_output(capsys)
import suds import suds.sax.document import suds.sax.parser from testutils.assertion import assert_no_output from testutils.compare_sax import CompareSAX import pytest from six import text_type, u import xml.sax # CompareSAX class uses Python assertions to report failed comparison results # so we need to skip the tests in this module if Python assertions have been # disabled in the CompareSAX implementation module. skip_test_if_CompareSAX_assertions_disabled = pytest.mark.skipif( not CompareSAX.assertions_enabled(), reason="CompareSAX assertions disabled") @skip_test_if_CompareSAX_assertions_disabled @pytest.mark.parametrize("data", ("", "<bad1/><bad2/>", '<bad a="1" a="1"/>', "<bad><bad>xml</document></bad>")) def test_failed_parsing(data, capsys): pytest.raises(xml.sax.SAXParseException, CompareSAX.data2data, data, data) assert_no_output(capsys) class TestMatched: """Successful CompareSAX matching tests.""" @skip_test_if_CompareSAX_assertions_disabled def test_empty_document(self, capsys):
def test_string_input_types(self, type1, type2, capsys): xml = "<a/>" CompareSAX.data2data(type1(xml), type2(xml)) assert_no_output(capsys)
def test_data2data(self, data1, data2, capsys): CompareSAX.data2data(data1, data2) assert_no_output(capsys)
def test_empty_document(self, capsys): a = suds.sax.document.Document() b = suds.sax.document.Document() CompareSAX.document2document(a, b) assert_no_output(capsys)
import suds.sax.document import suds.sax.parser from testutils.assertion import assert_no_output from testutils.compare_sax import CompareSAX import pytest from six import text_type, u import xml.sax # CompareSAX class uses Python assertions to report failed comparison results # so we need to skip the tests in this module if Python assertions have been # disabled in the CompareSAX implementation module. skip_test_if_CompareSAX_assertions_disabled = pytest.mark.skipif( not CompareSAX.assertions_enabled(), reason="CompareSAX assertions disabled") @skip_test_if_CompareSAX_assertions_disabled @pytest.mark.parametrize("data", ( "", "<bad1/><bad2/>", '<bad a="1" a="1"/>', "<bad><bad>xml</document></bad>")) def test_failed_parsing(data, capsys): pytest.raises(xml.sax.SAXParseException, CompareSAX.data2data, data, data) assert_no_output(capsys) class TestMatched: