Beispiel #1
0
 def test_get_no_version(self):
     event_queue = Queue()
     settings = XMPPSettings()
     settings["event_queue"] = event_queue
     client = RosterClient(settings)
     dispatcher = EventDispatcher(settings, [client])
     self.assertIsNone(client.roster)
     self.assertTrue(event_queue.empty())
     processor = Processor([client])
     stream = DummyStream(ElementTree.XML(EMPTY_FEATURES),
                                             JID("[email protected]/Test"))
     event = AuthorizedEvent(JID("[email protected]/Test"))
     event.stream = stream
     event_queue.put(event)
     dispatcher.dispatch()
     self.assertEqual(len(processor.stanzas_sent), 1)
     stanza = processor.stanzas_sent[0]
     self.assertEqual(stanza.stanza_type, "get")
     self.assertIsNone(stanza.to_jid, None)
     xml = stanza.as_xml()
     self.assertEqual(xml[0].tag, "{jabber:iq:roster}query")
     self.assertEqual(len(xml[0]), 0)
     payload = stanza.get_payload(RosterPayload)
     self.assertEqual(len(payload), 0)
     self.assertIsNone(payload.version, None)
     response = stanza.make_result_response()
     item1 = RosterItem(JID("*****@*****.**"))
     item2 = RosterItem(JID("*****@*****.**"))
     payload = RosterPayload([item1, item2], None)
     response.set_payload(payload)
     processor.uplink_receive(response)
     self.assertIsNotNone(client.roster)
     self.assertEqual(len(client.roster), 2)
     self.assertTrue(JID("*****@*****.**") in client.roster)
     self.assertTrue(JID("*****@*****.**") in client.roster)
     self.assertIsNone(client.roster.version)
     event = event_queue.get_nowait()
     self.assertIsInstance(event, RosterReceivedEvent)
     self.assertEqual(event.roster_client, client)
     self.assertEqual(event.roster, client.roster)
Beispiel #2
0
 def test_get_error(self):
     event_queue = Queue()
     settings = XMPPSettings()
     settings["event_queue"] = event_queue
     client = RosterClient(settings)
     dispatcher = EventDispatcher(settings, [client])
     self.assertIsNone(client.roster)
     self.assertTrue(event_queue.empty())
     processor = Processor([client])
     stream = DummyStream(ElementTree.XML(EMPTY_FEATURES),
                                             JID("[email protected]/Test"))
     event = AuthorizedEvent(JID("[email protected]/Test"))
     event.stream = stream
     event_queue.put(event)
     dispatcher.dispatch()
     stanza = processor.stanzas_sent[0]
     response = stanza.make_error_response("item-not-found")
     processor.uplink_receive(response)
     self.assertIsNone(client.roster)
     event = event_queue.get_nowait()
     self.assertIsInstance(event, RosterNotReceivedEvent)
     self.assertEqual(event.roster_client, client)
     self.assertIsNotNone(event.stanza)
     self.assertEqual(event.stanza.stanza_id, response.stanza_id)