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 testAction(self): message = Message() message['body'] = 'action 1 or 2?' for (id_, label) in [('1', 'action 1'), ('2', 'action 2')]: act = stanza.Action() act['id'] = id_ act['label'] = label message.append(act) self.check(message, """ <message> <body>action 1 or 2?</body> <action xmlns="urn:xmpp:tmp:quick-response" id="1" label="action 1" /> <action xmlns="urn:xmpp:tmp:quick-response" id="2" label="action 2" /> </message> """, use_values=False)
def testResponse(self): message = Message() message['body'] = 'Reply 1 or 2?' for (value, label) in [('1', 'Rep 1'), ('2', 'Rep 2')]: rep = stanza.Response() rep['value'] = value rep['label'] = label message.append(rep) self.check(message, """ <message> <body>Reply 1 or 2?</body> <response xmlns="urn:xmpp:tmp:quick-response" value="1" label="Rep 1" /> <response xmlns="urn:xmpp:tmp:quick-response" value="2" label="Rep 2" /> </message> """, use_values=False)
def testActionSelected(self): message = Message() message['action_selected']['id'] = 'act1' self.check(message, """ <message> <action-selected xmlns="urn:xmpp:tmp:quick-response" id="act1" /> </message> """, use_values=False)
def testRetracted(self): message = Message() message['retracted']['stamp'] = '2019-09-20T23:09:32Z' message['retracted']['origin_id']['id'] = 'originid' self.check(message, """ <message> <retracted stamp="2019-09-20T23:09:32Z" xmlns="urn:xmpp:message-retract:0"> <origin-id xmlns="urn:xmpp:sid:0" id="originid"/> </retracted> </message> """)
def testRetract(self): message = Message() message['apply_to']['id'] = 'some-id' message['apply_to']['retract'] self.check(message, """ <message> <apply-to xmlns="urn:xmpp:fasten:0" id="some-id"> <retract xmlns="urn:xmpp:message-retract:0"/> </apply-to> </message> """, use_values=False)
def testModerated(self): message = Message() message['moderated']['by'] = JID('toto@titi') message['moderated']['retracted']['stamp'] = '2019-09-20T23:09:32Z' message['moderated']['reason'] = 'R' self.check( message, """ <message> <moderated xmlns="urn:xmpp:message-moderate:0" by="toto@titi"> <retracted stamp="2019-09-20T23:09:32Z" xmlns="urn:xmpp:message-retract:0" /> <reason>R</reason> </moderated> </message> """)
def testMIXMessage(self): msg = Message() msg['type'] = 'groupchat' msg['body'] = 'This is a message body' msg['mix']['nick'] = 'A nick' msg['mix']['jid'] = JID('*****@*****.**') self.check(msg, """ <message type="groupchat"> <body>This is a message body</body> <mix xmlns="urn:xmpp:mix:core:1"> <nick>A nick</nick> <jid>[email protected]</jid> </mix> </message> """)
def testFastenExternal(self): message = Message() message['apply_to']['id'] = 'some-id' message['apply_to'].xml.append( ET.fromstring('<test xmlns="urn:tmp:test">Test</test>')) message['apply_to']['external']['name'] = 'body' message['body'] = 'Toto' self.check(message, """ <message> <apply-to xmlns="urn:xmpp:fasten:0" id="some-id"> <test xmlns="urn:tmp:test">Test</test> <external name='body'/> </apply-to> <body>Toto</body> </message> """, use_values=False)
def testMakeOutgoingMessage(self): xmlstring = """ <message xmlns="jabber:component:accept" from='pubsub.capulet.lit' to='capulet.net'> <privilege xmlns='urn:xmpp:privilege:1'> <forwarded xmlns='urn:xmpp:forward:0'> <message from="*****@*****.**" to="*****@*****.**" xmlns="jabber:client"> <body>I do not hate you</body> </message> </forwarded> </privilege> </message> """ msg = Message() msg["from"] = "*****@*****.**" msg["to"] = "*****@*****.**" msg["body"] = "I do not hate you" priv_msg = self.xmpp["xep_0356"]._make_privileged_message(msg) self.check(priv_msg, xmlstring, use_values=False)
def testInvite(self): message = Message() message['from'] = 'user@server' message['to'] = 'muc@service' message['muc']['invite']['to'] = JID('user2@server2') message['muc']['invite']['reason'] = 'Hey' self.check(message, """ <message from='user@server' to='muc@service'> <x xmlns='http://jabber.org/protocol/muc#user'> <invite to='user2@server2'> <reason>Hey</reason> </invite> </x> </message> """, use_values=False)
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")
def testMIXNewParticipant(self): msg = Message() msg['pubsub_event']['items']['node'] = 'urn:xmpp:mix:nodes:participants' item = pstanza.EventItem() item['id'] = '123456' item['mix_participant']['jid'] = JID('*****@*****.**') item['mix_participant']['nick'] = 'Titi' msg['pubsub_event']['items'].append(item) self.check(msg, """ <message> <event xmlns='http://jabber.org/protocol/pubsub#event'> <items node='urn:xmpp:mix:nodes:participants'> <item id='123456'> <participant xmlns='urn:xmpp:mix:core:1'> <jid>[email protected]</jid> <nick>Titi</nick> </participant> </item> </items> </event> </message> """, use_values=False)