Skip to content
This repository has been archived by the owner on Feb 19, 2020. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Added more presence stream tests.
Tests auto_authorize=False, and got_online.
  • Loading branch information
legastero committed Oct 25, 2010
1 parent ac330b5 commit 2eff35c
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tests/test_stream_presence.py
Expand Up @@ -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
Expand Down Expand Up @@ -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.