'Test that presence events are raised.'

def test_presence_events(self):

    events = []
    ptypes = ['available', 'away', 'dnd', 'xa', 'chat', 'unavailable', 'subscribe', 'subscribed', 'unsubscribe', 'unsubscribed']
    for ptype in ptypes:
        handler = (lambda p: events.append(p['type']))
        self.xmpp.add_event_handler(('presence_%s' % ptype), handler)
    self.recv('\n                                        <presence    />\n                                ')
    self.recv('\n                                        <presence><show>away</show></presence>\n                                ')
    self.recv('\n                                        <presence><show>dnd</show></presence>\n                                ')
    self.recv('\n                                        <presence><show>xa</show></presence>\n                                ')
    self.recv('\n                                        <presence><show>chat</show></presence>\n                                ')
    self.recv('\n                                        <presence    type="unavailable"    />\n                                ')
    self.recv('\n                                        <presence    type="subscribe"    />\n                                ')
    self.recv('\n                                        <presence    type="subscribed"    />\n                                ')
    self.recv('\n                                        <presence    type="unsubscribe"    />\n                                ')
    self.recv('\n                                        <presence    type="unsubscribed"    />\n                                ')
    time.sleep(0.5)
    self.assertEqual(events, ptypes, ('Not    all    events    raised:    %s' % events))
