mirror of
https://github.com/correl/SleekXMPP.git
synced 2024-11-30 19:19:55 +00:00
Added more presence stream tests.
Tests auto_authorize=False, and got_online.
This commit is contained in:
parent
ac330b5c6c
commit
2eff35cc7a
1 changed files with 59 additions and 0 deletions
|
@ -82,6 +82,32 @@ class TestStreamPresence(SleekTest):
|
||||||
self.assertEqual(events, ['got_offline'],
|
self.assertEqual(events, ['got_offline'],
|
||||||
"Got offline incorrectly triggered: %s" % events)
|
"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):
|
def testAutoAuthorizeAndSubscribe(self):
|
||||||
"""
|
"""
|
||||||
Test auto authorizing and auto subscribing
|
Test auto authorizing and auto subscribing
|
||||||
|
@ -124,5 +150,38 @@ class TestStreamPresence(SleekTest):
|
||||||
self.assertEqual(events, expected,
|
self.assertEqual(events, expected,
|
||||||
"Incorrect events triggered: %s" % events)
|
"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)
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamPresence)
|
||||||
|
|
Loading…
Reference in a new issue