def test_retrieve_torrent(client, testfiles): torrent = testfiles / "test_single.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() client.add(torrent_data, testfiles, fast_resume=False) verify_torrent_state(client, [{ "infohash": infohash, }]) retrieved_torrent_data = bdecode(client.retrieve_torrentfile(infohash)) assert (hashlib.sha1(bencode( retrieved_torrent_data[b"info"])).hexdigest() == infohash) client.remove(infohash)
def test_get_files_singlefile(client, testfiles): torrent = testfiles / "test_single.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() client.add(torrent_data, testfiles, fast_resume=False) verify_torrent_state( client, [{ "infohash": infohash, "name": "file_a.txt", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) assert client.get_download_path(infohash) == testfiles files = sorted(client.get_files(infohash), key=lambda x: x.path) expected_filenames = sorted([ "file_a.txt", ]) assert len(files) == len(expected_filenames) for f, name in zip(files, expected_filenames): assert f.path == name assert f.progress == 100.0 assert f.size == 11 client.remove(infohash) verify_torrent_state(client, []) assert (testfiles / "file_a.txt").exists()
def test_add_torrent_multifile_no_add_name_to_folder_different_name( client, testfiles): new_path = Path(testfiles) / "New-Some-Release" (testfiles / "Some-Release").rename(new_path) torrent = testfiles / "Some-Release.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() client.add( torrent_data, new_path, fast_resume=False, add_name_to_folder=False, minimum_expected_data="full", ) verify_torrent_state( client, [{ "infohash": infohash, "state": TorrentState.ACTIVE, "progress": 100.0 }], ) assert client.get_download_path(infohash) == testfiles / "New-Some-Release" client.remove(infohash) verify_torrent_state(client, []) assert (Path(testfiles) / "New-Some-Release").exists()
def test_move_multifile_no_add_name_to_folder( source_client_name, target_client_name, testfiles, deluge_client, qbittorrent_client, rtorrent_client, transmission_client, ): clients = { "deluge": deluge_client, "qbittorrent": qbittorrent_client, "rtorrent": rtorrent_client, "transmission": transmission_client, } source_client = clients[source_client_name] target_client = clients[target_client_name] new_path = Path(testfiles) / "New-Some-Release" (testfiles / "Some-Release").rename(new_path) torrent = testfiles / "Some-Release.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() source_client.add( torrent_data, new_path, fast_resume=False, add_name_to_folder=False, minimum_expected_data="full", ) verify_torrent_state( source_client, [{ "infohash": infohash, "state": TorrentState.ACTIVE, "progress": 100.0, }], ) move_torrent(infohash, source_client, target_client) verify_torrent_state( target_client, [{ "infohash": infohash, "state": TorrentState.ACTIVE, "progress": 100.0, }], ) verify_torrent_state( source_client, [], ) target_client.remove(infohash) verify_torrent_state( target_client, [], )
def test_move_singlefile( source_client_name, target_client_name, testfiles, deluge_client, qbittorrent_client, rtorrent_client, transmission_client, ): clients = { "deluge": deluge_client, "qbittorrent": qbittorrent_client, "rtorrent": rtorrent_client, "transmission": transmission_client, } source_client = clients[source_client_name] target_client = clients[target_client_name] torrent = testfiles / "test_single.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() source_client.add(torrent_data, testfiles, fast_resume=False) verify_torrent_state( source_client, [{ "infohash": infohash, "name": "file_a.txt", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) move_torrent(infohash, source_client, target_client) verify_torrent_state( target_client, [{ "infohash": infohash, "name": "file_a.txt", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) verify_torrent_state( source_client, [], ) target_client.remove(infohash) verify_torrent_state( target_client, [], )
def test_start_stop(client, testfiles): torrent = testfiles / "Some-Release.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() client.add(torrent_data, testfiles, fast_resume=False) time.sleep(2) # Weird bug with Deluge verify_torrent_state( client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) client.stop(infohash) verify_torrent_state( client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.STOPPED, "progress": 100.0, }], ) client.start(infohash) verify_torrent_state( client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) client.remove(infohash) verify_torrent_state(client, []) assert (testfiles / "Some-Release").exists()
def test_add_torrent_singlefile_no_data(client, testfiles, tmp_path): torrent = testfiles / "test_single.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() client.add(torrent_data, tmp_path, fast_resume=False, add_name_to_folder=False) verify_torrent_state(client, [{ "infohash": infohash, "state": TorrentState.ACTIVE, "progress": 0.0, }]) assert client.get_download_path(infohash) == Path(tmp_path) client.remove(infohash) verify_torrent_state(client, []) assert (testfiles / "file_a.txt").exists()
def test_get_files_multifile(client, testfiles): torrent = testfiles / "Some-Release.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() client.add(torrent_data, testfiles, fast_resume=False) verify_torrent_state( client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) assert client.get_download_path(infohash) == testfiles / "Some-Release" files = sorted(client.get_files(infohash), key=lambda x: x.path) expected_filenames = sorted([ "Sample/some-rls.mkv", "Subs/some-subs.rar", "Subs/some-subs.sfv", "some-rls.nfo", "some-rls.r00", "some-rls.r01", "some-rls.r02", "some-rls.r03", "some-rls.r04", "some-rls.r05", "some-rls.r06", "some-rls.rar", "some-rls.sfv", ]) assert len(files) == len(expected_filenames) for f, name in zip(files, expected_filenames): assert f.path == name assert f.progress == 100.0 assert f.size == 12 client.remove(infohash) verify_torrent_state(client, []) assert (testfiles / "Some-Release").exists()
def test_add_torrent_multifile(client, testfiles): torrent = testfiles / "Some-Release.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() client.add(torrent_data, testfiles, fast_resume=False) verify_torrent_state( client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) assert client.get_download_path(infohash) == testfiles / "Some-Release" client.remove(infohash) verify_torrent_state(client, []) assert (testfiles / "Some-Release").exists()
def test_move_multifile_stopped( source_client_name, target_client_name, testfiles, deluge_client, qbittorrent_client, rtorrent_client, transmission_client, ): clients = { "deluge": deluge_client, "qbittorrent": qbittorrent_client, "rtorrent": rtorrent_client, "transmission": transmission_client, } source_client = clients[source_client_name] target_client = clients[target_client_name] torrent = testfiles / "Some-Release.torrent" torrent_data = bdecode(torrent.read_bytes()) infohash = hashlib.sha1(bencode(torrent_data[b"info"])).hexdigest() source_client.add(torrent_data, testfiles, fast_resume=False) time.sleep(2) # Weird bug with Deluge verify_torrent_state( source_client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) source_client.stop(infohash) verify_torrent_state( source_client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.STOPPED, "progress": 100.0, }], ) move_torrent(infohash, source_client, target_client) verify_torrent_state( target_client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.STOPPED, }], ) target_client.start(infohash) verify_torrent_state( target_client, [{ "infohash": infohash, "name": "Some-Release", "state": TorrentState.ACTIVE, "progress": 100.0, }], ) verify_torrent_state( source_client, [], ) target_client.remove(infohash) verify_torrent_state( target_client, [], )