Permalink
Browse files

Added more presence stream tests.

Tests auto_authorize=False, and got_online.
  • Loading branch information...
1 parent ac330b5 commit 2eff35cc7a05ca0978befb6754921e1f6d8c270d @legastero legastero committed Oct 25, 2010
Showing with 59 additions and 0 deletions.
  1. +59 −0 tests/test_stream_presence.py
@@ -82,6 +82,32 @@ def got_offline(presence):
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 @@ def changed_subscription(p):
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)

0 comments on commit 2eff35c

Please sign in to comment.