'Setup a second peer that contains some search results.'

@blocking_call_on_reactor_thread
@inlineCallbacks
def setup_peer(self):

    self.setUpPreSession()
    self.config2 = self.config.copy()
    self.config2.set_state_dir(self.getStateDir(2))
    self.session2 = Session(self.config2, ignore_singleton=True)
    (yield self.session2.start())
    self.dispersy2 = self.session2.get_dispersy_instance()
    @blocking_call_on_reactor_thread
    @inlineCallbacks
    def unload_communities():
        for community in self.dispersy.get_communities():
            if (isinstance(community, SearchCommunity) or isinstance(community, AllChannelCommunity)):
                (yield community.unload_community())
        for community in self.dispersy2.get_communities():
            if (isinstance(community, SearchCommunity) or isinstance(community, AllChannelCommunity)):
                (yield community.unload_community())
    @blocking_call_on_reactor_thread
    def load_communities():
        self.search_community = self.dispersy.define_auto_load(SearchCommunityTests, self.session.dispersy_member, load=True, kargs={'tribler_session': self.session})[0]
        self.dispersy2.define_auto_load(SearchCommunityTests, self.session2.dispersy_member, load=True, kargs={'tribler_session': self.session2})
        self.allchannel_community = self.dispersy.define_auto_load(AllChannelCommunityTests, self.session.dispersy_member, load=True, kargs={'tribler_session': self.session})[0]
        self.dispersy2.define_auto_load(AllChannelCommunityTests, self.session2.dispersy_member, load=True, kargs={'tribler_session': self.session2})
    (yield unload_communities())
    load_communities()
    self.search_community.add_discovered_candidate(Candidate(self.dispersy2.lan_address, tunnel=False))
    self.allchannel_community.add_discovered_candidate(Candidate(self.dispersy2.lan_address, tunnel=False))
    torrent_db_handler = self.session2.open_dbhandler(NTFY_TORRENTS)
    torrent_db_handler.addExternalTorrentNoDef((str(unichr(97)) * 20), 'test    test', [('Test.txt', 1337)], [], 1337)
    torrent_db_handler.updateTorrent((str(unichr(97)) * 20), is_collected=1)
    channel_db_handler = self.session2.open_dbhandler(NTFY_CHANNELCAST)
    channel_db_handler.on_channel_from_dispersy(('f' * 20), 42, 'test', 'channel    for    unit    tests')
    torrent_list = [[1, 1, 1, ('a' * 40).decode('hex'), 1460000000, 'ubuntu-torrent.iso', [['file1.txt', 42]], []]]
    channel_db_handler.on_torrents_from_dispersy(torrent_list)
    channel_db_handler = self.session.open_dbhandler(NTFY_CHANNELCAST)
    channel_db_handler.on_channel_from_dispersy(('f' * 20), 42, 'test', 'channel    for    unit    tests')
