diff --git a/tests/test_stream_presence.py b/tests/test_stream_presence.py index 994d4e1..c5d5cec 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(""" + + """) + + # 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(""" + + """) + + self.stream_send_presence(""" + + """) + + expected = set(('presence_subscribe', 'changed_subscription')) + self.assertEqual(events, expected, + "Incorrect events triggered: %s" % events) + suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPresence)