예제 #1
0
def test_check_rpc_version_for_args():
    m = mock.Mock(return_value={"hello": "world"})
    with mock.patch("transmission_rpc.client.Client._request", m):
        c = Client()
        c.protocol_version = 7
        with pytest.raises(ValueError):
            c.add_torrent(magnet_url, cookies="")
예제 #2
0
def test_torrent_get_files(tr_client: Client):
    with open("tests/fixtures/iso.torrent", "rb") as f:
        tr_client.add_torrent(f)
    assert len(tr_client.get_torrents()) == 1, "transmission should has at least 1 task"
    for torrent in tr_client.get_torrents():
        for file in torrent.files():
            assert isinstance(file, File)
예제 #3
0
def test_client_add_kwargs():
    m = mock.Mock(return_value={"hello": "workd"})
    with mock.patch("transmission_rpc.client.Client._request", m):
        c = Client()
        c.protocol_version = 15
        c.add_torrent(
            torrent_url,
            download_dir="dd",
            files_unwanted=[1, 2],
            files_wanted=[3, 4],
            paused=False,
            peer_limit=5,
            priority_high=[6],
            priority_low=[7],
            priority_normal=[8],
            cookies="coo",
            bandwidthPriority=4,
        )
    m.assert_called_with(
        "torrent-add",
        {
            "filename": torrent_url,
            "download-dir": "dd",
            "files-unwanted": [1, 2],
            "files-wanted": [3, 4],
            "paused": False,
            "peer-limit": 5,
            "priority-high": [6],
            "priority-low": [7],
            "priority-normal": [8],
            "cookies": "coo",
            "bandwidthPriority": 4,
        },
        timeout=None,
    )
예제 #4
0
def test_torrent_start_all(tr_client: Client, fake_hash_factory):
    tr_client.add_torrent(hash_to_magnet(fake_hash_factory()), paused=True, timeout=1)
    tr_client.add_torrent(hash_to_magnet(fake_hash_factory()), paused=True, timeout=1)
    for torrent in tr_client.get_torrents():
        assert torrent.status == 'stopped', 'all torrent should be stopped'

    tr_client.start_all()
    for torrent in tr_client.get_torrents():
        assert torrent.status == 'downloading', 'all torrent should be downloading'
예제 #5
0
def test_real_get_files(tr_client: Client):
    with open("tests/fixtures/iso.torrent", "rb") as f:
        tr_client.add_torrent(f)
    assert len(tr_client.get_torrents()) == 1, "transmission should has at least 1 task"
    for tid, files in tr_client.get_files(1).items():
        assert files
        assert isinstance(tid, int)
        for file in files:
            assert isinstance(file, File)
예제 #6
0
def test_real_add_torrent_file_protocol(tr_client: Client):
    fs = os.path.abspath(
        os.path.join(
            os.path.dirname(__file__, ),
            "fixtures/iso.torrent",
        ))
    tr_client.add_torrent("file://" + fs)
    assert len(tr_client.get_torrents()
               ) == 1, "transmission should has at least 1 task"
예제 #7
0
def test_check_rpc_version_for_args():
    m = mock.Mock(return_value={"hello": "world"})
    with mock.patch("transmission_rpc.client.Client._request", m):
        c = Client()
        c.protocol_version = 7
        with pytest.raises(
            TransmissionVersionError,
            match='Method "torrent-add" Argument "cookies" does not exist in version 7',
        ):
            c.add_torrent(magnet_url, cookies="")
예제 #8
0
def test_real_stop(tr_client: Client, fake_hash_factory):
    info_hash = fake_hash_factory()
    url = hash_to_magnet(info_hash)
    tr_client.add_torrent(url)
    tr_client.stop_torrent(info_hash)
    assert len(tr_client.get_torrents()) == 1, 'transmission should has only 1 task'
    ret = False

    for _ in range(50):
        time.sleep(0.2)
        if tr_client.get_torrents()[0].status == 'stopped':
            ret = True
            break

    assert ret, 'torrent should be stopped'
예제 #9
0
def test_real_add_torrent_base64(tr_client: Client):
    with open("tests/fixtures/iso.torrent", "rb") as f:
        tr_client.add_torrent(base64.b64encode(f.read()).decode())
    assert len(tr_client.get_torrents()
               ) == 1, "transmission should has at least 1 task"
예제 #10
0
def test_real_add_torrent_base64(tr_client: Client):
    with open("tests/fixtures/iso.torrent", "rb") as f:
        with pytest.warns(DeprecationWarning, match="base64"):
            tr_client.add_torrent(base64.b64encode(f.read()).decode())
    assert len(tr_client.get_torrents()) == 1, "transmission should has at least 1 task"
예제 #11
0
def test_real_add_magnet(tr_client: Client):
    tr_client.add_torrent(magnet_url)
    assert len(tr_client.get_torrents()
               ) == 1, "transmission should has at least 1 task"
예제 #12
0
def test_real_add_torrent_fd(tr_client: Client):
    with open("tests/fixtures/iso.torrent", "rb") as f:
        tr_client.add_torrent(f)
    assert len(tr_client.get_torrents()
               ) == 1, "transmission should has at least 1 task"
예제 #13
0
def test_real_add_magnet(tr_client: Client):
    torrent_url = 'magnet:?xt=urn:btih:e84213a794f3ccd890382a54a64ca68b7e925433'
    tr_client.add_torrent(torrent_url)
    assert len(tr_client.get_torrents()
               ) == 1, 'transmission should has at least 1 task'
예제 #14
0
def test_torrent_attr_type(tr_client: Client, fake_hash_factory):
    with open("tests/fixtures/iso.torrent", "rb") as f:
        tr_client.add_torrent(f)
    for torrent in tr_client.get_torrents():
        assert isinstance(torrent.id, int)
        assert isinstance(torrent.name, str)
예제 #15
0
def test_real_add_torrent_not_endswith_torrent(tr_client: Client):
    # The shorten url is ref to
    # "https://github.com/Trim21/transmission-rpc/raw/master/tests/fixtures/iso.torrent"
    tr_client.add_torrent("https://git.io/JJUVt")
    assert len(tr_client.get_torrents()
               ) == 1, "transmission should has at least 1 task"
예제 #16
0
def test_real_add_torrent_http(tr_client: Client):
    tr_client.add_torrent(
        "https://github.com/Trim21/transmission-rpc/raw/master/tests/fixtures/iso.torrent"
    )
    assert len(tr_client.get_torrents()
               ) == 1, "transmission should has at least 1 task"
예제 #17
0
def test_real_add_torrent_http(tr_client: Client):
    tr_client.add_torrent(
        'https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrent'
    )
    assert len(tr_client.get_torrents()) == 1, 'transmission should has at least 1 task'