'Testing whether downloading a torrent from another peer is successful'

@deferred(timeout=20)
@skipIf((sys.platform == 'win32'), 'chmod    does    not    work    on    Windows')
def test_torrent_download(self):

    session1_port = self.session.config.get_dispersy_port()
    def start_download(_):
        candidate = Candidate(('127.0.0.1', session1_port), False)
        self.session2.lm.rtorrent_handler.download_torrent(candidate, self.infohashes[0])
        self.session2.lm.rtorrent_handler.download_torrent(candidate, self.infohashes[1], user_callback=do_check_download)
    def do_check_download(_):
        for (i, infohash_str) in enumerate(self.infohash_strs):
            self._logger.info(u'Checking...    %s', self.file_names[i])
            for _ in self.session2.lm.torrent_store.iterkeys():
                self.assertTrue((infohash_str in self.session2.lm.torrent_store), u'Failed    to    download    torrent    file    1.')
        self._logger.info(u'Torrent    files    1    and    2    downloaded    successfully.')
        self.test_deferred.callback(None)
    self.infohash_strs = ['41aea20908363a80d44234e8fef07fab506cd3b4', '45a647b1120ed9fe7f793e17585efb4b0efdf1a5']
    for (i, infohash) in enumerate(self.infohash_strs):
        self.infohashes[i] = infohash.decode('hex')
        self.file_names[i] = file_name = (u'%s.torrent' % infohash)
        with open(os.path.join(TESTS_DATA_DIR, file_name), 'r') as torrent_file:
            self.session.lm.torrent_store.put(infohash, torrent_file.read())
    self.setup_downloader().addCallback(start_download)
    return self.test_deferred
