def test_update(atp: lt.add_torrent_params, conn: apsw.Connection) -> None: atp.save_path = "original" resumedb.insert_or_ignore_resume_data(atp, conn) if atp.ti is not None: resumedb.update_info(atp.ti, conn) atp.save_path = "updated" resumedb.update_resume_data(atp, conn) atps = list(resumedb.iter_resume_data_from_db(conn)) assert len(atps) == 1 (got, ) = atps assert got.save_path == "updated" assert resumedb.info_hashes(got) == resumedb.info_hashes(atp) assert_ti_equal(got.ti, atp.ti)
def resume_data(atp: lt.add_torrent_params) -> bytes: if atp.ti is None: with ltpy.translate_exceptions(): return lt.write_resume_data_buf(atp) atp = copy(atp) atp.ti = None with ltpy.translate_exceptions(): return lt.write_resume_data_buf(atp)
async def configure_swarm(atp: lt.add_torrent_params) -> None: assert fetch is not None # helps mypy bencoded = await fetch() bdecoded = cast(Dict[bytes, Any], lt.bdecode(bencoded)) atp.ti = lt.torrent_info(bdecoded) # TODO: top-level publish await concurrency.to_thread( receive_bdecoded_info, torrent_entry_id, bdecoded[b"info"] )
def test_update_resume_data(ti: lt.torrent_info, atp: lt.add_torrent_params, conn: apsw.Connection) -> None: resumedb.update_info_hashes(ti.info_hashes(), conn) resumedb.update_info(ti, conn) atp.save_path = "expected" resumedb.update_resume_data(atp, conn) atps = list(resumedb.iter_resume_data_from_db(conn)) assert len(atps) == 1 (got, ) = atps assert got.save_path == "expected" assert resumedb.info_hashes(got) == resumedb.info_hashes(atp)
def test_update_resume_data_delete(ti: lt.torrent_info, atp: lt.add_torrent_params, conn: apsw.Connection, valid: bool) -> None: if valid: resumedb.update_info_hashes(ti.info_hashes(), conn) resumedb.update_info(ti, conn) atp.save_path = "expected" resumedb.update_resume_data(atp, conn) resumedb.delete(ti.info_hashes(), conn) atps = list(resumedb.iter_resume_data_from_db(conn)) assert atps == []
def configure_atp(self, atp: lt.add_torrent_params) -> None: # this is necessary so that # atp == read_resume_data(write_resume_data(atp)) atp.info_hash = self.sha1_hash atp.ti = self.torrent_info()
async def configure_all(atp: lt.add_torrent_params) -> None: assert atp.info_hashes == INFO_HASHES atp.trackers = [TRACKER]