def test_map_binding_operation_messages_with_style_rpc( self, mock_build_envelope_class, mock_build_message_class): definitions = Definitions() operation = BindingOperation() port_operation = PortTypeOperation() name = "Add" namespace = "someNS" target = ClassFactory.create() message = ClassFactory.create() style = "rpc" mock_build_message_class.return_value = message mock_build_envelope_class.return_value = target operation.input = BindingMessage() port_operation.input = PortTypeMessage() result = DefinitionsMapper.map_binding_operation_messages( definitions, operation, port_operation, name, style, namespace) self.maxDiff = None self.assertEqual([message, target], list(result)) mock_build_message_class.assert_called_once_with( definitions, port_operation.input) mock_build_envelope_class.assert_called_once_with( definitions, operation.input, port_operation.input, f"{name}_input", style, namespace, )
def test_map_binding(self, mock_attributes, mock_find_operation, mock_map_binding_operation): definitions = Definitions() port_type = PortType(name="Calc") binding = Binding( type="zaa:zoo", operations=[ BindingOperation(name="ADD"), BindingOperation(name="SUB") ], ) port_type_add = PortTypeOperation(name="PortAdd") port_type_sub = PortTypeOperation(name="PortSub") classes = [ ClassFactory.list(2), ClassFactory.list(2), ] mock_map_binding_operation.side_effect = classes mock_find_operation.side_effect = [port_type_add, port_type_sub] mock_attributes.side_effect = [ { "soapAction": "add" }, { "soapAction": "sub" }, ] config = {"foo": "bar"} result = DefinitionsMapper.map_binding(definitions, binding, port_type, config) self.assertIsInstance(result, Generator) self.assertEqual(classes[0] + classes[1], list(result)) mock_find_operation.assert_has_calls( [mock.call("ADD"), mock.call("SUB")]) self.assertEqual(2, mock_attributes.call_count) config_add = {"soapAction": "add", **config} config_sub = {"soapAction": "sub", **config} mock_map_binding_operation.assert_has_calls([ mock.call( definitions, binding.operations[0], port_type_add, config_add, "Calc", ), mock.call( definitions, binding.operations[1], port_type_sub, config_sub, "Calc", ), ])
def test_build_envelope_fault(self): body = ClassFactory.create(qname="Body") target = ClassFactory.create() target.inner.append(body) port_type_operation = PortTypeOperation() definitions = Definitions() 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", "detail"] ] self.assertEqual(1, len(body.attrs)) self.assertEqual(expected_fault_attr, body.attrs[0]) self.assertEqual(expected_fault_attrs, body.inner[0].attrs)
def test_build_envelope_fault_raises_error_if_missing_inner_body(self): target = ClassFactory.create() operation = PortTypeOperation() definitions = Definitions() with self.assertRaises(StopIteration): DefinitionsMapper.build_envelope_fault(definitions, operation, target)
def test_find_operating(self): res = PortTypeOperation(name="foo") obj = PortType(operations=[res]) self.assertEqual(res, obj.find_operation("foo")) with self.assertRaises(DefinitionsValueError) as cm: obj.find_operation("nope") self.assertEqual("Unknown PortTypeOperation name: nope", str(cm.exception))
def test_map_binding_operation(self, mock_operation_namespace, mock_map_binding_operation_messages): definitions = Definitions(location="foo.wsdl", target_namespace="xsdata") operation = BindingOperation(name="Add") operation.ns_map["foo"] = "bar" port_operation = PortTypeOperation() config = {"a": "one", "b": "two", "style": "rpc"} name = "Calc" namespace = "SomeNS" first = ClassFactory.create(qname="some_name_first", meta_name="Envelope") second = ClassFactory.create(qname="some_name_second", meta_name="Envelope") other = ClassFactory.create() service = ClassFactory.create( qname=build_qname("xsdata", "Calc_Add"), status=Status.PROCESSED, tag=Tag.BINDING_OPERATION, module="foo", package=None, ns_map={"foo": "bar"}, attrs=[ DefinitionsMapper.build_attr("a", str(DataType.STRING), native=True, default="one"), DefinitionsMapper.build_attr("b", str(DataType.STRING), native=True, default="two"), DefinitionsMapper.build_attr("style", str(DataType.STRING), native=True, default="rpc"), DefinitionsMapper.build_attr("first", first.qname), DefinitionsMapper.build_attr("second", second.qname), ], ) mock_operation_namespace.return_value = namespace mock_map_binding_operation_messages.return_value = [ first, second, other ] result = DefinitionsMapper.map_binding_operation( definitions, operation, port_operation, config, name) expected = [first, second, other, service] self.assertIsInstance(result, Generator) self.assertEqual(expected, list(result)) mock_operation_namespace.assert_called_once_with(config) mock_map_binding_operation_messages.assert_called_once_with( definitions, operation, port_operation, service.name, "rpc", namespace)
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)
def test_map_binding_operation_messages(self, mock_build_envelope_class, mock_build_envelope_fault): definitions = Definitions() operation = BindingOperation() port_operation = PortTypeOperation() name = "Add" namespace = "someNS" target = ClassFactory.create() style = "document" mock_build_envelope_class.return_value = target result = DefinitionsMapper.map_binding_operation_messages( definitions, operation, port_operation, name, style, namespace) self.assertIsInstance(result, Generator) self.assertEqual(0, len(list(result))) operation.input = BindingMessage() port_operation.input = PortTypeMessage() result = DefinitionsMapper.map_binding_operation_messages( definitions, operation, port_operation, name, style, namespace) self.maxDiff = None self.assertEqual([target], list(result)) operation.output = BindingMessage() port_operation.output = PortTypeMessage() result = DefinitionsMapper.map_binding_operation_messages( definitions, operation, port_operation, name, style, namespace) self.assertEqual([target, target], list(result)) mock_build_envelope_class.assert_has_calls([ mock.call( definitions, operation.input, port_operation.input, f"{name}_input", style, namespace, ), mock.call( definitions, operation.input, port_operation.input, f"{name}_input", style, namespace, ), mock.call( definitions, operation.output, port_operation.output, f"{name}_output", style, namespace, ), ]) mock_build_envelope_fault.assert_called_once_with( definitions, port_operation, target)