First pass at integrating the new roster manager.

This commit is contained in:
Lance Stout
2010-10-26 23:47:17 -04:00
parent b888610525
commit 65aa6573df
9 changed files with 515 additions and 136 deletions

View File

@@ -48,10 +48,14 @@ class TestRosterStanzas(SleekTest):
'user@example.com': {
'name': 'User',
'subscription': 'both',
'ask': '',
'approved': '',
'groups': ['Friends', 'Coworkers']},
'otheruser@example.com': {
'name': 'Other User',
'subscription': 'both',
'ask': '',
'approved': '',
'groups': []}}
debug = "Roster items don't match after retrieval."
debug += "\nReturned: %s" % str(iq['roster']['items'])

View File

@@ -30,7 +30,9 @@ class TestStreamPresence(SleekTest):
self.xmpp.add_event_handler('presence_unavailable', unavailable)
self.stream_recv("""
<presence type="unavailable" from="otheruser@localhost" />
<presence from="otheruser@localhost"
to="tester@localhost"
type="unavailable" />
""")
# Give event queue time to process.
@@ -68,12 +70,14 @@ class TestStreamPresence(SleekTest):
# Contact comes online.
self.stream_recv("""
<presence from="otheruser@localhost/foobar" />
<presence from="otheruser@localhost/foobar"
to="tester@localhost" />
""")
# Contact goes offline, should trigger got_offline.
self.stream_recv("""
<presence from="otheruser@localhost/foobar"
to="tester@localhost"
type="unavailable" />
""")
@@ -99,7 +103,8 @@ class TestStreamPresence(SleekTest):
self.xmpp.add_event_handler('got_online', got_online)
self.stream_recv("""
<presence from="user@localhost" />
<presence from="user@localhost"
to="tester@localhost" />
""")
# Give event queue time to process.
@@ -136,15 +141,23 @@ class TestStreamPresence(SleekTest):
self.xmpp.auto_subscribe = True
self.stream_recv("""
<presence from="user@localhost" type="subscribe" />
<presence from="user@localhost"
to="tester@localhost"
type="subscribe" />
""")
self.stream_send_presence("""
<presence to="user@localhost" type="subscribed" />
<presence to="user@localhost"
type="subscribed" />
""")
self.stream_send_presence("""
<presence to="user@localhost" type="subscribe" />
<presence to="user@localhost" />
""")
self.stream_send_presence("""
<presence to="user@localhost"
type="subscribe" />
""")
expected = set(('presence_subscribe', 'changed_subscription'))
@@ -170,14 +183,17 @@ class TestStreamPresence(SleekTest):
presence_subscribe)
# With this setting we should reject all subscriptions.
self.xmpp.auto_authorize = False
self.xmpp.rosters['tester@localhost'].auto_authorize = False
self.stream_recv("""
<presence from="user@localhost" type="subscribe" />
<presence from="user@localhost"
to="tester@localhost"
type="subscribe" />
""")
self.stream_send_presence("""
<presence to="user@localhost" type="unsubscribed" />
<presence to="user@localhost"
type="unsubscribed" />
""")
expected = set(('presence_subscribe', 'changed_subscription'))

View File

@@ -13,8 +13,7 @@ class TestStreamRoster(SleekTest):
def testGetRoster(self):
"""Test handling roster requests."""
self.stream_start(mode='client')
self.failUnless(self.xmpp.roster == {}, "Initial roster not empty.")
self.stream_start(mode='client', jid='tester@localhost')
# Since get_roster blocks, we need to run it in a thread.
t = threading.Thread(name='get_roster', target=self.xmpp.get_roster)
@@ -26,11 +25,12 @@ class TestStreamRoster(SleekTest):
</iq>
""")
self.stream_recv("""
<iq type="result" id="1">
<iq to='tester@localhost' type="result" id="1">
<query xmlns="jabber:iq:roster">
<item jid="user@localhost"
name="User"
subscription="both">
subscription="from"
ask="subscribe">
<group>Friends</group>
<group>Examples</group>
</item>
@@ -41,21 +41,20 @@ class TestStreamRoster(SleekTest):
# Wait for get_roster to return.
t.join()
roster = {'user@localhost': {'name': 'User',
'subscription': 'both',
'groups': ['Friends', 'Examples'],
'presence': {},
'in_roster': True}}
self.failUnless(self.xmpp.roster == roster,
"Unexpected roster values: %s" % self.xmpp.roster)
print self.xmpp.rosters['tester@localhost']['user@localhost']._state
self.check_roster('tester@localhost', 'user@localhost',
name='User',
subscription='from',
afrom=True,
pending_out=True,
groups=['Friends', 'Examples'])
def testRosterSet(self):
"""Test handling pushed roster updates."""
self.stream_start(mode='client')
self.failUnless(self.xmpp.roster == {}, "Initial roster not empty.")
self.stream_start(mode='client', jid='tester@localhost')
self.stream_recv("""
<iq type="set" id="1">
<iq to='tester@localhost' type="set" id="1">
<query xmlns="jabber:iq:roster">
<item jid="user@localhost"
name="User"
@@ -72,15 +71,10 @@ class TestStreamRoster(SleekTest):
</iq>
""")
roster = {'user@localhost': {'name': 'User',
'subscription': 'both',
'groups': ['Friends', 'Examples'],
'presence': {},
'in_roster': True}}
self.failUnless(self.xmpp.roster == roster,
"Unexpected roster values: %s" % self.xmpp.roster)
self.check_roster('tester@localhost', 'user@localhost',
name='User',
subscription='both',
groups=['Friends', 'Examples'])
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamRoster)