'Test handling roster requests.'

def testGetRoster(self):

    self.stream_start(mode=u'client', jid=u'tester@localhost')
    roster_updates = []
    self.xmpp.add_event_handler(u'roster_update', roster_updates.append)
    t = threading.Thread(name=u'get_roster', target=self.xmpp.get_roster)
    t.start()
    self.send(u'\n                                        <iq    type="get"    id="1">\n                                                <query    xmlns="jabber:iq:roster"    />\n                                        </iq>\n                                ')
    self.recv(u'\n                                        <iq    to=\'tester@localhost\'    type="result"    id="1">\n                                                <query    xmlns="jabber:iq:roster">\n                                                        <item    jid="user@localhost"\n                                                                                name="User"\n                                                                                subscription="from"\n                                                                                ask="subscribe">\n                                                                <group>Friends</group>\n                                                                <group>Examples</group>\n                                                        </item>\n                                                </query>\n                                        </iq>\n                                ')
    t.join()
    time.sleep(0.1)
    self.check_roster(u'tester@localhost', u'user@localhost', name=u'User', subscription=u'from', afrom=True, pending_out=True, groups=[u'Friends', u'Examples'])
    self.failUnless((len(roster_updates) == 1), (u'Wrong    number    of    roster_update    events    fired:    %s    (should    be    1)' % len(roster_updates)))
