2010-10-24 16:53:14 +00:00
|
|
|
from sleekxmpp.test import *
|
|
|
|
import time
|
|
|
|
import threading
|
|
|
|
|
|
|
|
|
|
|
|
class TestStreamRoster(SleekTest):
|
|
|
|
"""
|
|
|
|
Test handling roster updates.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
self.stream_close()
|
|
|
|
|
|
|
|
def testGetRoster(self):
|
|
|
|
"""Test handling roster requests."""
|
2010-10-27 03:47:17 +00:00
|
|
|
self.stream_start(mode='client', jid='tester@localhost')
|
2010-10-24 16:53:14 +00:00
|
|
|
|
|
|
|
# Since get_roster blocks, we need to run it in a thread.
|
|
|
|
t = threading.Thread(name='get_roster', target=self.xmpp.get_roster)
|
|
|
|
t.start()
|
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.send("""
|
2010-10-24 16:53:14 +00:00
|
|
|
<iq type="get" id="1">
|
|
|
|
<query xmlns="jabber:iq:roster" />
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-11-05 18:45:58 +00:00
|
|
|
self.recv("""
|
2010-10-27 03:47:17 +00:00
|
|
|
<iq to='tester@localhost' type="result" id="1">
|
2010-10-24 16:53:14 +00:00
|
|
|
<query xmlns="jabber:iq:roster">
|
|
|
|
<item jid="user@localhost"
|
|
|
|
name="User"
|
2010-10-27 03:47:17 +00:00
|
|
|
subscription="from"
|
|
|
|
ask="subscribe">
|
2010-10-24 16:53:14 +00:00
|
|
|
<group>Friends</group>
|
|
|
|
<group>Examples</group>
|
|
|
|
</item>
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
|
|
|
# Wait for get_roster to return.
|
|
|
|
t.join()
|
|
|
|
|
2010-10-27 03:47:17 +00:00
|
|
|
self.check_roster('tester@localhost', 'user@localhost',
|
|
|
|
name='User',
|
|
|
|
subscription='from',
|
|
|
|
afrom=True,
|
|
|
|
pending_out=True,
|
|
|
|
groups=['Friends', 'Examples'])
|
2010-10-24 16:53:14 +00:00
|
|
|
|
|
|
|
def testRosterSet(self):
|
|
|
|
"""Test handling pushed roster updates."""
|
2010-10-27 03:47:17 +00:00
|
|
|
self.stream_start(mode='client', jid='tester@localhost')
|
2010-10-24 16:53:14 +00:00
|
|
|
|
2010-11-05 18:45:58 +00:00
|
|
|
self.recv("""
|
2010-10-27 03:47:17 +00:00
|
|
|
<iq to='tester@localhost' type="set" id="1">
|
2010-10-24 16:53:14 +00:00
|
|
|
<query xmlns="jabber:iq:roster">
|
|
|
|
<item jid="user@localhost"
|
|
|
|
name="User"
|
|
|
|
subscription="both">
|
|
|
|
<group>Friends</group>
|
|
|
|
<group>Examples</group>
|
|
|
|
</item>
|
|
|
|
</query>
|
|
|
|
</iq>
|
|
|
|
""")
|
2010-11-05 18:45:58 +00:00
|
|
|
self.send("""
|
2010-10-24 16:53:14 +00:00
|
|
|
<iq type="result" id="1">
|
|
|
|
<query xmlns="jabber:iq:roster" />
|
|
|
|
</iq>
|
|
|
|
""")
|
|
|
|
|
2010-10-27 03:47:17 +00:00
|
|
|
self.check_roster('tester@localhost', 'user@localhost',
|
|
|
|
name='User',
|
|
|
|
subscription='both',
|
|
|
|
groups=['Friends', 'Examples'])
|
2010-10-24 16:53:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamRoster)
|