コード例 #1
0
ファイル: test_definitions.py プロジェクト: neriusmika/xsdata
    def test_build_envelope_fault_with_detail_messages(self):
        body = ClassFactory.create(qname="Body")
        target = ClassFactory.create()
        target.inner.append(body)

        port_type_operation = PortTypeOperation()
        port_type_operation.faults.append(PortTypeMessage(message="x:foo"))
        port_type_operation.faults.append(PortTypeMessage(message="x:bar"))

        definitions = Definitions()
        definitions.messages.append(
            Message(name="foo", parts=[Part(element="fooEl")]))
        definitions.messages.append(
            Message(name="bar", parts=[Part(element="barEl")]))

        DefinitionsMapper.build_envelope_fault(definitions,
                                               port_type_operation, target)
        expected_fault_attr = DefinitionsMapper.build_attr(
            "Fault",
            body.inner[0].qname,
            forward=True,
            namespace=target.namespace)
        str_qname = str(DataType.STRING)
        expected_fault_attrs = [
            DefinitionsMapper.build_attr(name,
                                         str_qname,
                                         native=True,
                                         namespace="")
            for name in ["faultcode", "faultstring", "faultactor"]
        ]

        expected_fault_attrs.append(
            DefinitionsMapper.build_attr("detail",
                                         body.inner[0].inner[0].qname,
                                         forward=True,
                                         namespace=""))

        expected_fault_detail_attrs = [
            DefinitionsMapper.build_attr(name,
                                         qname=name,
                                         namespace=target.namespace,
                                         native=False)
            for name in ["fooEl", "barEl"]
        ]

        self.assertEqual(1, len(body.attrs))
        self.assertEqual(expected_fault_attr, body.attrs[0])
        self.assertEqual(expected_fault_attrs, body.inner[0].attrs)
        self.assertEqual(expected_fault_detail_attrs,
                         body.inner[0].inner[0].attrs)
コード例 #2
0
    def test_merge(self):
        target = Definitions()
        source = Definitions()
        source.types = Types()
        source.messages.append(Message())
        source.port_types.append(PortType())
        source.bindings.append(Binding())
        source.services.append(Service())
        source.extended.append(AnyElement())

        source_two = copy.deepcopy(source)
        source_two.types.schemas.append(Schema())

        target.merge(source)
        self.assertEqual(source.types, target.types)
        self.assertEqual(0, len(target.types.schemas))
        self.assertEqual(1, len(target.messages))
        self.assertEqual(1, len(target.port_types))
        self.assertEqual(1, len(target.bindings))
        self.assertEqual(1, len(target.services))
        self.assertEqual(1, len(target.extended))

        target.merge(source_two)
        target.merge(Definitions())
        self.assertEqual(1, len(target.types.schemas))
        self.assertEqual(2, len(target.messages))
        self.assertEqual(2, len(target.port_types))
        self.assertEqual(2, len(target.bindings))
        self.assertEqual(2, len(target.services))
        self.assertEqual(2, len(target.extended))
コード例 #3
0
ファイル: test_definitions.py プロジェクト: neriusmika/xsdata
    def test_map_binding_message_parts_with_original_message(
            self, mock_find_message, mock_create_message_attributes):
        definitions = Definitions
        message_name = "foo:bar"
        ns_map = {}
        message = Message(
            name="session",
            parts=[
                Part(name="token", element="foo:token"),
                Part(name="messageId", type="id"),
                Part(name="another", type="id"),
            ],
        )
        extended = AnyElement()
        mock_create_message_attributes.return_value = AttrFactory.list(2)
        mock_find_message.return_value = message

        actual = DefinitionsMapper.map_binding_message_parts(
            definitions, message_name, extended, ns_map)

        self.assertIsInstance(actual, Generator)
        self.assertEqual(2, len(list(actual)))

        mock_create_message_attributes.assert_called_once_with(
            message.parts, ns_map)
        mock_find_message.assert_called_once_with("bar")
コード例 #4
0
    def test_find_message(self):
        res = Message(name="foo")
        obj = Definitions(messages=[res])

        self.assertEqual(res, obj.find_message("foo"))

        with self.assertRaises(DefinitionsValueError) as cm:
            obj.find_message("nope")

        self.assertEqual("Unknown Message name: nope", str(cm.exception))
コード例 #5
0
    def test_build_message_class(self, mock_create_message_attributes):
        message = Message(name="bar", parts=[Part()])
        message.ns_map["foo"] = "bar"
        definitions = Definitions(
            messages=[message], target_namespace="xsdata", location="foo.wsdl"
        )
        port_type_message = PortTypeMessage(message="foo:bar")

        attrs = AttrFactory.list(2)
        mock_create_message_attributes.return_value = attrs
        actual = DefinitionsMapper.build_message_class(definitions, port_type_message)
        expected = Class(
            qname=build_qname("xsdata", "bar"),
            status=Status.PROCESSED,
            type=Element,
            module="foo",
            ns_map=message.ns_map,
            attrs=attrs,
        )
        self.assertEqual(expected, actual)