summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-10-24 19:57:07 -0400
committerLance Stout <lancestout@gmail.com>2010-10-24 19:57:07 -0400
commit46ffa8e9fe02b355426eb1b044dbdd8fffe20549 (patch)
treef762f2a6ee8653838b5e2704ee614f07d0083e09
parent03847497cc30b95708124d6c643d0ea2266196ef (diff)
downloadslixmpp-46ffa8e9fe02b355426eb1b044dbdd8fffe20549.tar.gz
slixmpp-46ffa8e9fe02b355426eb1b044dbdd8fffe20549.tar.bz2
slixmpp-46ffa8e9fe02b355426eb1b044dbdd8fffe20549.tar.xz
slixmpp-46ffa8e9fe02b355426eb1b044dbdd8fffe20549.zip
Added stream tests for presence events.
First batch of tests, currently focuses on the got_offline event.
-rw-r--r--tests/test_stream_presence.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py
new file mode 100644
index 00000000..135d8eed
--- /dev/null
+++ b/tests/test_stream_presence.py
@@ -0,0 +1,86 @@
+import time
+from sleekxmpp.test import *
+
+
+class TestStreamPresence(SleekTest):
+ """
+ Test handling roster updates.
+ """
+
+ def tearDown(self):
+ self.stream_close()
+
+ def testInitialUnavailablePresences(self):
+ """
+ Test receiving unavailable presences from JIDs that
+ are not online.
+ """
+ events = set()
+
+ def got_offline(presence):
+ # The got_offline event should not be triggered.
+ events.add('got_offline')
+
+ def unavailable(presence):
+ # The presence_unavailable event should be triggered.
+ events.add('unavailable')
+
+ self.stream_start()
+ self.xmpp.add_event_handler('got_offline', got_offline)
+ self.xmpp.add_event_handler('presence_unavailable', unavailable)
+
+ self.stream_recv("""
+ <presence type="unavailable" from="otheruser@localhost" />
+ """)
+
+ # Give event queue time to process.
+ time.sleep(0.1)
+
+ self.assertEqual(events, set(('unavailable',)),
+ "Got offline incorrectly triggered: %s." % events)
+
+ def testGotOffline(self):
+ """Test that got_offline is triggered properly."""
+ events = []
+ def got_offline(presence):
+ events.append('got_offline')
+
+ self.stream_start()
+ self.xmpp.add_event_handler('got_offline', got_offline)
+
+ # Setup roster. Use a 'set' instead of 'result' so we
+ # don't have to handle get_roster() blocking.
+ #
+ # We use the stream to initialize the roster to make
+ # the test independent of the roster implementation.
+ self.stream_recv("""
+ <iq type="set">
+ <query xmlns="jabber:iq:roster">
+ <item jid="otheruser@localhost"
+ name="Other User"
+ subscription="both">
+ <group>Testers</group>
+ </item>
+ </query>
+ </iq>
+ """)
+
+ # Contact comes online.
+ self.stream_recv("""
+ <presence from="otheruser@localhost/foobar" />
+ """)
+
+ # Contact goes offline, should trigger got_offline.
+ self.stream_recv("""
+ <presence from="otheruser@localhost/foobar"
+ type="unavailable" />
+ """)
+
+ # Give event queue time to process.
+ time.sleep(0.1)
+
+ self.assertEqual(events, ['got_offline'],
+ "Got offline incorrectly triggered: %s" % events)
+
+
+suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPresence)