Beispiel #1
0
 def testtransport_message_listener_with_announce_to_same_node(self):
     """
     Test to check the message_listener method with announce to the same of the signal class.
     """
     sig_dict, signal = self.setup_vars_mocks()
     transport = XmppTransport.factory(
         "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal,
         signal._presence_publisher, None, None)
     transport._jid_cache = JidCache(signal, 30)
     register_stanza_plugin(Message, IpopSignal)
     msg = Message()
     msg["from"] = "ipop"
     transport.boundjid.full = "edgevpn"
     msg["ipop"]["type"] = "announce"
     msg["ipop"]["payload"] = "123#456"
     sig_dict["Signal"]["NodeId"] = "456"
     transport.send_msg = MagicMock()
     transport._presence_publisher = Mock()
     transport._presence_publisher.post_update = MagicMock()
     transport.message_listener(msg)
     self.assertEqual(transport._jid_cache.lookup("456"), None)
     transport.send_msg.assert_not_called()
     transport._presence_publisher.post_update.assert_not_called()
     print(
         "Passed : testtransport_message_listener_with_announce_to_same_node"
     )
Beispiel #2
0
 def testtransport_message_listener_with_uid(self):
     """
     Test to check the message_listener method with uid of the signal class.
     """
     sig_dict, signal = self.setup_vars_mocks()
     transport = XmppTransport.factory(
         "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal,
         signal._presence_publisher, None, None)
     transport._jid_cache = JidCache(signal, 30)
     register_stanza_plugin(Message, IpopSignal)
     msg = Message()
     msg["from"] = "ipop"
     transport.boundjid.full = "edgevpn"
     msg["ipop"]["type"] = "uid!"
     msg["ipop"]["payload"] = "123#456"
     item = {0: "invk", 1: {"ActionTag": "1"}, 2: 5}
     q = Queue()
     q.put_nowait(item)
     outgoing_rem_acts = {"456": q}
     transport._outgoing_rem_acts = outgoing_rem_acts
     transport.send_msg = MagicMock()
     transport.message_listener(msg)
     assert transport._jid_cache.lookup("456") == "123"
     transport.send_msg.assert_called_once()
     print("Passed : testtransport_presence_event_handler_with_uid")
Beispiel #3
0
    def __init__(self, jid, password):
        sleekxmpp.ClientXMPP.__init__(self, jid, password)
        sleekxmpp.register_stanza_plugin(Message, Json)

        # The session_start event will be triggered when
        # the bot establishes its connection with the server
        # and the XML streams are ready for use. We want to
        # listen for this event so that we we can initialize
        # our roster.
        self.add_event_handler("session_start", self.start)

        # The message event is triggered whenever a message
        # stanza is received. Be aware that that includes
        # MUC messages and error messages.
        self.add_event_handler("message", self.message)
Beispiel #4
0
 def testtransport_send_message(self, msg_mock):
     """
     Test to check the send message method of transport instance of the signal class.
     """
     register_stanza_plugin(Message, IpopSignal)
     sig_dict, signal = self.setup_vars_mocks()
     transport = XmppTransport.factory(
         "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal,
         signal._presence_publisher, None, None)
     transport.registerHandler(
         Callback("ipop", StanzaPath("message/ipop"),
                  transport.message_listener))
     msg = transport.Message()
     msg_mock.return_value = msg
     msg.send = MagicMock()
     transport.send_msg("2", "invk", "Data")
     msg.send.assert_called_once()
     print("Passed : testtransport_send_message")
Beispiel #5
0
 def testtransport_message_listener_with_invk(self, mock_loads):
     """
     Test to check the message_listener method with invk to a different node of the signal class.
     """
     sig_dict, signal = self.setup_vars_mocks()
     mock_loads.return_value = MagicMock()
     transport = XmppTransport.factory(
         "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal,
         signal._presence_publisher, None, None)
     transport._jid_cache = JidCache(signal, 30)
     register_stanza_plugin(Message, IpopSignal)
     msg = Message()
     msg["from"] = "ipop"
     transport.boundjid.full = "edgevpn"
     msg["ipop"]["type"] = "invk"
     msg["ipop"]["payload"] = {"Action": "announce"}
     transport._sig.handle_remote_action = MagicMock()
     transport.message_listener(msg)
     mock_loads.assert_called_once()
     transport._sig.handle_remote_action.assert_called_once()
     print("Passed : testtransport_message_listener_with_invk")