def testsignal_timer_method(self): """ Test to check the timer method 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) rem_acts = {} jid_cache = JidCache(signal, 5) jid_cache.scavenge = MagicMock() signal.scavenge_pending_cbts = MagicMock() transport.event_loop = MagicMock() signal._circles = { "A0FB389": { "Announce": 0, "Transport": transport, "OutgoingRemoteActs": rem_acts, "JidCache": jid_cache } } signal._circles["A0FB389"][ "Transport"].event_loop.call_soon_threadsafe = MagicMock() signal.timer_method() signal._circles["A0FB389"][ "Transport"].event_loop.call_soon_threadsafe.assert_called_once() jid_cache.scavenge.assert_called_once() signal.scavenge_pending_cbts.assert_called_once() print("Passed : testsignal_timer_method")
def testsignal_resp_handler_remote_action(self): """ Test to check the handling remote action method with a response of the signal class. """ sig_dict, signal = self.setup_vars_mocks() cbt = CBT() cbt.request.params = {"RecipientId": "1", "OverlayId": "A0FB389"} jid_cache = JidCache(signal, 5) jid_cache.add_entry("1", "2345") transport = XmppTransport.factory( "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal, signal._presence_publisher, None, None) transport.send_msg = MagicMock() signal._circles = { "A0FB389": { "JidCache": jid_cache, "Transport": transport } } cbt.tag = "1" signal.submit_cbt(cbt) resp = CBT.Response() cbt.response = resp rem_act = {"InitiatorId": "1", "OverlayId": "A0FB389"} signal._remote_acts["1"] = rem_act signal.submit_cbt(cbt) signal.transmit_remote_act = MagicMock() signal.free_cbt = MagicMock() signal.resp_handler_remote_action(cbt) signal.transmit_remote_act.assert_called_once() signal.free_cbt.assert_called_once() print("Passed : testsignal_resp_handler_remote_action")
def testjid_cache_add_lookup_entry(self): """ Test to check the lookup method of the jid-cache of the signal class. """ sig_dict, signal = self.setup_vars_mocks() jid_cache = JidCache(signal, 30) jid_cache.add_entry("123", "2345") assert jid_cache.lookup("123") == "2345" print("Passed : testjid_cache_add_lookup_entry")
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, EvioSignal) msg = Message() msg["from"] = "ipop" transport.boundjid.full = "edgevpn" msg["evio"]["type"] = "announce" msg["evio"]["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" )
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, EvioSignal) msg = Message() msg["from"] = "ipop" transport.boundjid.full = "edgevpn" msg["evio"]["type"] = "uid!" msg["evio"]["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")
def testjid_cache_scavenge(self): """ Test to check the scavenge method of the jid-cache of the signal class. """ sig_dict, signal = self.setup_vars_mocks() jid_cache = JidCache(signal, 5) jid_cache.add_entry("123", "2345") assert jid_cache.lookup("123") == "2345" sleep(5) jid_cache.scavenge() assert jid_cache.lookup("123") is None print("Passed : testjid_cache_scavenge")
def testtransmit_remote_act(self): """ Test to check the transmit remote action method of the signal class. """ rem_act = {"InitiatorId": "1", "OverlayId": "A0FB389"} sig_dict, signal = self.setup_vars_mocks() jid_cache = JidCache(signal, 5) jid_cache.add_entry("1", "2345") transport = XmppTransport.factory( "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal, signal._presence_publisher, None, None) transport.send_msg = MagicMock() signal._circles = { "A0FB389": { "JidCache": jid_cache, "Transport": transport } } signal.transmit_remote_act(rem_act, "1", "invk") transport.send_msg.assert_called_once() print("Passed : testtransmit_remote_act")
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, EvioSignal) msg = Message() msg["from"] = "ipop" transport.boundjid.full = "edgevpn" msg["evio"]["type"] = "invk" msg["evio"]["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")