'Test auto authorizing and auto subscribing
to subscription requests.'

def testAutoAuthorizeAndSubscribe(self):

    events = set()
    def presence_subscribe(p):
        events.add('presence_subscribe')
    def changed_subscription(p):
        events.add('changed_subscription')
    self.xmpp.add_event_handler('changed_subscription', changed_subscription)
    self.xmpp.add_event_handler('presence_subscribe', presence_subscribe)
    self.xmpp.auto_authorize = True
    self.xmpp.auto_subscribe = True
    self.recv('\n                                        <presence    from="user@localhost"\n                                                                                to="tester@localhost"\n                                                                                type="subscribe"    />\n                                ')
    self.send('\n                                        <presence    to="user@localhost"\n                                                                                type="subscribed"    />\n                                ')
    self.send('\n                                        <presence    to="user@localhost"    />\n                                ')
    self.send('\n                                        <presence    to="user@localhost"\n                                                                                type="subscribe"    />\n                                ')
    expected = set(('presence_subscribe', 'changed_subscription'))
    self.assertEqual(events, expected, ('Incorrect    events    triggered:    %s' % events))
