Example #1
0
def encode_routing_result(msg: Message, result: IntermediateRoutingResult):
    global_parameters = result.target.parameters
    msg.params.update(global_parameters)
    if result.is_simple:
        msg.return_value = result.target.target
    else:
        msg.return_value = "fork"
        fork_parameters = calltargets_to_callfork_params(
            result.fork_targets, global_parameters)
        msg.params.update(fork_parameters)
    return msg
Example #2
0
 async def _retrieve_from_cache_for(self, msg: Message):
     called = "lateroute/" + msg.params.get("called")
     result = await self._routing_cache.retrieve(called)
     if result is None:
         # This is an invalid entry, answer the message but with invalid result
         msg.result = ""
         self.answer_message(msg, True)
     else:
         msg = ywsd.yate.encode_routing_result(msg, result)
         self.answer_message(msg, True)
Example #3
0
    def test_universal_watch_handler_recv_message(self):
        callback_mock = MagicMock()
        handler = yate.WatchHandler("", callback_mock)
        handler.installed = True
        self.y._watch_handlers[""] = handler

        msg = Message("0xDEAD.1", None, "chan.dtmf", "val",
                      {"target": "wave/2"}, True, True)
        self.y._handle_yate_message(msg)

        callback_mock.assert_called_with(msg)
Example #4
0
    def test_installed_message_handler_dispatch(self):
        y = YateBase()
        callback_mock = MagicMock()
        mh = yate.MessageHandler("call.execute", 80, callback_mock, None, None)
        mh.installed = True
        y._message_handlers["call.execute"] = mh

        msg = Message("0xdeadc0de", 4711, "call.execute", "false", {
            "caller": "me",
            "target": "0815"
        })
        self.assertEqual("message", msg.msg_type)
        self.assertFalse(msg.reply)

        y._handle_yate_message(msg)
        callback_mock.assert_called_with(msg)

        callback_mock.reset_mock()
        msg2 = Message("0xdeadbeef", 4712, "chan.attach", "false", {})
        y._handle_yate_message(msg2)
        callback_mock.assert_not_called()
Example #5
0
    def test_message_answer_mechanism(self, mock_method):
        callback_mock = MagicMock()
        mh = yate.MessageHandler("call.execute", 80, callback_mock, None, None)
        mh.installed = True
        self.y._message_handlers["call.execute"] = mh

        msg = Message("0xdeadc0de", 4711, "call.execute", "false", {
            "caller": "me",
            "target": "0815"
        })
        self.y._handle_yate_message(msg)
        callback_mock.assert_called_with(msg)

        msg.params["caller"] = "you"
        self.y.answer_message(msg, True)
        self.assertGreaterEqual(len(mock_method.mock_calls), 1)
        answer_raw = mock_method.call_args[0][0]
        self.assertTrue(
            answer_raw.startswith(
                b"%%<message:0xdeadc0de:true:call.execute:false:"))
        self.assertTrue(answer_raw.find(b"caller=you") >= 0)
        self.assertTrue(answer_raw.find(b"target=0815") >= 0)
Example #6
0
    def test_message_response_callback_mechanism(self):
        callback_mock = MagicMock()
        self.y._get_timestamp.return_value = 42

        msg = MessageRequest("chan.attach", {"target": "sip/2"}, "resultVal")
        self.y.send_message(msg, callback_mock)
        self.assertIn(self.y._session_id + ".1", self.y._requested_messages)

        msg_reply = Message(self.y._session_id + ".1",
                            42,
                            "chan.attach",
                            "result", {
                                "target": "sip/2",
                                "notify": "true"
                            },
                            reply=True)
        self.y._handle_yate_message(msg_reply)

        self.assertNotIn(self.y._session_id + ".1", self.y._requested_messages)
        callback_mock.assert_called_with(msg, msg_reply)