'Testing whether various events are coming through the events endpoints'

@deferred(timeout=20)
def test_events(self):

    self.messages_to_wait_for = 20
    def send_notifications(_):
        self.session.lm.api_manager.root_endpoint.events_endpoint.start_new_query()
        results_dict = {'keywords': ['test'], 'result_list': [(('a',) * 10)]}
        self.session.notifier.notify(SIGNAL_TORRENT, SIGNAL_ON_SEARCH_RESULTS, None, results_dict)
        self.session.notifier.notify(SIGNAL_CHANNEL, SIGNAL_ON_SEARCH_RESULTS, None, results_dict)
        self.session.notifier.notify(NTFY_UPGRADER, NTFY_STARTED, None, None)
        self.session.notifier.notify(NTFY_UPGRADER_TICK, NTFY_STARTED, None, None)
        self.session.notifier.notify(NTFY_UPGRADER, NTFY_FINISHED, None, None)
        self.session.notifier.notify(NTFY_WATCH_FOLDER_CORRUPT_TORRENT, NTFY_INSERT, None, None)
        self.session.notifier.notify(NTFY_NEW_VERSION, NTFY_INSERT, None, None)
        self.session.notifier.notify(NTFY_CHANNEL, NTFY_DISCOVERED, None, None)
        self.session.notifier.notify(NTFY_TORRENT, NTFY_DISCOVERED, None, {'a': 'Invalid    character    \xa1'})
        self.session.notifier.notify(NTFY_TORRENT, NTFY_DELETE, None, {'a': 'b'})
        self.session.notifier.notify(NTFY_TORRENT, NTFY_FINISHED, ('a' * 10), None)
        self.session.notifier.notify(NTFY_TORRENT, NTFY_ERROR, ('a' * 10), 'This    is    an    error    message')
        self.session.notifier.notify(NTFY_MARKET_ON_ASK, NTFY_UPDATE, None, {'a': 'b'})
        self.session.notifier.notify(NTFY_MARKET_ON_BID, NTFY_UPDATE, None, {'a': 'b'})
        self.session.notifier.notify(NTFY_MARKET_ON_ASK_TIMEOUT, NTFY_UPDATE, None, {'a': 'b'})
        self.session.notifier.notify(NTFY_MARKET_ON_BID_TIMEOUT, NTFY_UPDATE, None, {'a': 'b'})
        self.session.notifier.notify(NTFY_MARKET_ON_TRANSACTION_COMPLETE, NTFY_UPDATE, None, {'a': 'b'})
        self.session.notifier.notify(NTFY_MARKET_ON_PAYMENT_RECEIVED, NTFY_UPDATE, None, {'a': 'b'})
        self.session.notifier.notify(NTFY_MARKET_ON_PAYMENT_SENT, NTFY_UPDATE, None, {'a': 'b'})
        self.session.lm.api_manager.root_endpoint.events_endpoint.on_tribler_exception('hi')
    self.socket_open_deferred.addCallback(send_notifications)
    return self.events_deferred
