Exemplo n.º 1
0
    def test_add_content_piece_length(self):
        """
        Add a single file with piece length to a TorrentDef
        """
        t = TorrentDef()
        fn = TESTS_DATA_DIR / VIDEO_FILE_NAME
        t.add_content(fn)
        t.set_piece_length(2**16)
        t.save()

        metainfo = t.get_metainfo()
        self.assertEqual(metainfo[b'info'][b'piece length'], 2**16)
Exemplo n.º 2
0
def create_dummy_sql_dumb(file_name):
    """
    Create a TorrentDef with a dummy sql dumb file
    :param file_name: full path to the file
    :return: tdef
    """
    with open(file_name, 'w') as fp:
        fp.write("BEGIN TRANSACTION;")
        fp.write("CREATE TABLE IF NOT EXISTS option(key TEXT PRIMARY KEY, value BLOB);")
        fp.write("INSERT OR REPLACE INTO option(key, value) VALUES('database_version', '0');")
        fp.write("COMMIT;")
    tdef = TorrentDef()
    tdef.add_content(file_name)
    tdef.set_piece_length(2 ** 16)
    tdef.save()
    return tdef
Exemplo n.º 3
0
    async def add_torrent(self, piece_length=1024):
        [srchandle, sourcefn] = mkstemp(dir=TESTS_DIR)
        data = b''.join([i.to_bytes(2, byteorder='big') for i in range(1000)])
        os.write(srchandle, data)
        os.close(srchandle)

        tdef = TorrentDef()
        tdef.add_content(sourcefn)
        tdef.set_piece_length(piece_length)
        torrentfn = self.session.config.get_state_dir() / "gen.torrent"
        tdef.save(torrentfn)

        dscfg = DownloadConfig()
        destdir = Path(sourcefn).parent
        dscfg.set_dest_dir(destdir)

        download = self.session.dlmgr.start_download(tdef=tdef, config=dscfg)
        await download.wait_for_status(DLSTATUS_SEEDING)
        return tdef.get_infohash(), data
Exemplo n.º 4
0
    async def add_torrent(self):
        [srchandle, sourcefn] = mkstemp(dir=TESTS_DIR)
        self.data = b'\xFF' * self.size  # pylint: disable=attribute-defined-outside-init
        os.write(srchandle, self.data)
        os.close(srchandle)

        tdef = TorrentDef()
        tdef.add_content(sourcefn)
        tdef.set_piece_length(self.piece_len)
        torrentfn = self.session.config.get_state_dir() / "gen.torrent"
        tdef.save(torrentfn)

        dscfg = DownloadConfig()
        destdir = Path(sourcefn).parent
        dscfg.set_dest_dir(destdir)

        self.download = self.session.dlmgr.start_download(tdef=tdef,
                                                          config=dscfg)  # pylint: disable=attribute-defined-outside-init
        await self.download.wait_for_status(DLSTATUS_SEEDING)
        self.infohash = tdef.get_infohash()  # pylint: disable=attribute-defined-outside-init
Exemplo n.º 5
0
 def test_set_piece_length_invalid_type(self):
     t = TorrentDef()
     t.set_piece_length("20")