Esempio n. 1
0
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)
Esempio n. 2
0
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()
Esempio n. 3
0
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()
Esempio n. 4
0
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,
        [],
    )
Esempio n. 5
0
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,
        [],
    )
Esempio n. 6
0
def test_add(client):
    r = client.post(
        "/add?destination_path=%2Ftmp%2Fhorse&fast_resume=true&add_name_to_folder=true&minimum_expected_data=full",
        content_type="multipart/form-data",
        headers=GLOBAL_CONFIG["headers"],
        data={"torrent": (BytesIO(TORRENT_DATA), "torrent")},
    )
    call_entry = GLOBAL_CONFIG["client"]._call_log[0]
    assert call_entry[0] == "add"
    assert call_entry[1] == bdecode(TORRENT_DATA)
    assert call_entry[2] == Path("/tmp/horse")
    assert call_entry[3] == True
    assert call_entry[4] == True
    assert call_entry[5] == "full"
    assert call_entry[6] == False
Esempio n. 7
0
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()
Esempio n. 8
0
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()
Esempio n. 9
0
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()
Esempio n. 10
0
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()
Esempio n. 11
0
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,
        [],
    )