summaryrefslogtreecommitdiff
path: root/tests/test_stream_presence.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2010-10-25 13:19:19 -0400
committerLance Stout <lancestout@gmail.com>2010-10-25 13:21:00 -0400
commit2eff35cc7a05ca0978befb6754921e1f6d8c270d (patch)
treef2a15380c94bbd10f6320bc61760dfabc977fa11 /tests/test_stream_presence.py
parentac330b5c6c7a24eda0e91d4fc70414cfff014545 (diff)
downloadslixmpp-2eff35cc7a05ca0978befb6754921e1f6d8c270d.tar.gz
slixmpp-2eff35cc7a05ca0978befb6754921e1f6d8c270d.tar.bz2
slixmpp-2eff35cc7a05ca0978befb6754921e1f6d8c270d.tar.xz
slixmpp-2eff35cc7a05ca0978befb6754921e1f6d8c270d.zip
Added more presence stream tests.
Tests auto_authorize=False, and got_online.
Diffstat (limited to 'tests/test_stream_presence.py')
-rw-r--r--tests/test_stream_presence.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py
index 994d4e17..c5d5cec2 100644
--- a/tests/test_stream_presence.py
+++ b/tests/test_stream_presence.py
@@ -82,6 +82,32 @@ class TestStreamPresence(SleekTest):
self.assertEqual(events, ['got_offline'],
"Got offline incorrectly triggered: %s" % events)
+ def testGotOnline(self):
+ """Test that got_online is triggered properly."""
+
+ events = set()
+
+ def presence_available(p):
+ events.add('presence_available')
+
+ def got_online(p):
+ events.add('got_online')
+
+ self.stream_start()
+ self.xmpp.add_event_handler('presence_available', presence_available)
+ self.xmpp.add_event_handler('got_online', got_online)
+
+ self.stream_recv("""
+ <presence from="user@localhost" />
+ """)
+
+ # Give event queue time to process.
+ time.sleep(0.1)
+
+ expected = set(('presence_available', 'got_online'))
+ self.assertEqual(events, expected,
+ "Incorrect events triggered: %s" % events)
+
def testAutoAuthorizeAndSubscribe(self):
"""
Test auto authorizing and auto subscribing
@@ -124,5 +150,38 @@ class TestStreamPresence(SleekTest):
self.assertEqual(events, expected,
"Incorrect events triggered: %s" % events)
+ def testNoAutoAuthorize(self):
+ """Test auto rejecting subscription requests."""
+
+ events = set()
+
+ def presence_subscribe(p):
+ events.add('presence_subscribe')
+
+ def changed_subscription(p):
+ events.add('changed_subscription')
+
+ self.stream_start(jid='tester@localhost')
+
+ self.xmpp.add_event_handler('changed_subscription',
+ changed_subscription)
+ self.xmpp.add_event_handler('presence_subscribe',
+ presence_subscribe)
+
+ # With this setting we should reject all subscriptions.
+ self.xmpp.auto_authorize = False
+
+ self.stream_recv("""
+ <presence from="user@localhost" type="subscribe" />
+ """)
+
+ self.stream_send_presence("""
+ <presence to="user@localhost" type="unsubscribed" />
+ """)
+
+ expected = set(('presence_subscribe', 'changed_subscription'))
+ self.assertEqual(events, expected,
+ "Incorrect events triggered: %s" % events)
+
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPresence)