Exemplo n.º 1
0
def test_toggle_first_last_piece_priority(api_version, orig_torrent,
                                          client_func):
    if v(api_version) > v("2.0.1"):
        current_setting = orig_torrent.f_l_piece_prio
        getattr(orig_torrent, client_func)()
        sleep(1)
        check(lambda: orig_torrent.info.f_l_piece_prio, not current_setting)
Exemplo n.º 2
0
def test_rename_file(api_version, orig_torrent, client_func, name):
    if is_version_less_than(api_version, '2.4.0', lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(orig_torrent, client_func)(file_id=0, new_file_name=name)
    else:
        getattr(orig_torrent, client_func)(file_id=0, new_file_name=name)
        check(lambda: orig_torrent.files[0].name, name)
Exemplo n.º 3
0
def test_toggle_first_last_piece_priority(api_version, orig_torrent,
                                          client_func):
    if is_version_less_than("2.0.1", api_version, lteq=False):
        current_setting = orig_torrent.f_l_piece_prio
        getattr(orig_torrent, client_func)()
        sleep(1)
        check(lambda: orig_torrent.info.f_l_piece_prio, not current_setting)
Exemplo n.º 4
0
def test_set_category(client, orig_torrent, client_func, category):
    client.torrents_create_category(category=category)
    getattr(orig_torrent, client_func)(category=category)
    check(lambda: orig_torrent.info.category.replace("+", " "),
          category,
          reverse=True)
    client.torrents_remove_categories(categories=category)
Exemplo n.º 5
0
def test_set_share_limits(api_version, orig_torrent, client_func):
    if is_version_less_than(api_version, "2.0.1", lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(orig_torrent, client_func)(ratio_limit=5, seeding_time_limit=100)
    else:
        getattr(orig_torrent, client_func)(ratio_limit=5, seeding_time_limit=100)
        check(lambda: orig_torrent.info.max_ratio, 5)
        check(lambda: orig_torrent.info.max_seeding_time, 100)
Exemplo n.º 6
0
def test_trackers(orig_torrent, trackers):
    assert isinstance(orig_torrent.trackers, TrackersList)
    assert "num_peers" in orig_torrent.trackers[-1]

    orig_torrent.trackers = trackers
    check(lambda: (t.url for t in orig_torrent.trackers),
          trackers,
          reverse=True)
Exemplo n.º 7
0
def test_pause_resume(client, orig_torrent):
    orig_torrent.pause()
    check(lambda: client.torrents_info(torrents_hashes=orig_torrent.hash)[0].
          state, ('stalledDL', 'pausedDL'),
          any=True)

    orig_torrent.resume()
    check(lambda: client.torrents_info(torrents_hashes=orig_torrent.hash)[0].
          state, ('pausedDL', ),
          negate=True)
Exemplo n.º 8
0
def test_state_enum(orig_torrent):
    assert orig_torrent.state_enum in TorrentStates
    assert orig_torrent.state_enum is not TorrentStates.UNKNOWN
    check(lambda: orig_torrent.state_enum.is_downloading, True)
    # simulate an unknown torrent.state
    orig_torrent.state = "gibberish"
    assert orig_torrent.state_enum is TorrentStates.UNKNOWN
    # restore torrent state
    orig_torrent.sync_local()
    check(lambda: orig_torrent.state_enum.is_downloading, True)
Exemplo n.º 9
0
def test_delete(client):
    client.torrents_add(urls=torrent1_url)
    check(lambda: [t.hash for t in client.torrents_info()],
          torrent1_hash,
          reverse=True)
    torrent = [t for t in client.torrents_info() if t.hash == torrent1_hash][0]
    sleep(1)
    torrent.delete(delete_files=True)
    check(lambda: [t.hash for t in client.torrents_info()],
          torrent1_hash,
          reverse=True,
          negate=True)
Exemplo n.º 10
0
def test_rename_file(api_version, app_version, new_torrent, client_func, name):
    if v(api_version) < v("2.4.0"):
        with pytest.raises(NotImplementedError):
            getattr(new_torrent, client_func)(file_id=0, new_file_name=name)
    else:
        getattr(new_torrent, client_func)(file_id=0, new_file_name=name)
        check(lambda: new_torrent.files[0].name, name)

    if v(app_version) >= v("v4.3.3"):
        curr_name = new_torrent.files[0].name
        getattr(new_torrent, client_func)(old_path=curr_name,
                                          new_path=name + "_new")
        check(lambda: new_torrent.files[0].name, name + "_new")
Exemplo n.º 11
0
def test_set_location(api_version, new_torrent, client_func):
    if is_version_less_than("2.0.1", api_version, lteq=False):
        exp = None
        for attempt in range(2):
            try:
                loc = path.expanduser("~/Downloads/3/")
                getattr(new_torrent, client_func)(loc)
                check(lambda: new_torrent.info.save_path, loc)
                break
            except AssertionError as e:
                exp = e
        if exp:
            raise exp
Exemplo n.º 12
0
def test_rename_file(api_version, app_version, new_torrent, client_func, name):
    if is_version_less_than(api_version, "2.4.0", lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(new_torrent, client_func)(file_id=0, new_file_name=name)
    else:
        getattr(new_torrent, client_func)(file_id=0, new_file_name=name)
        check(lambda: new_torrent.files[0].name, name)

    if is_version_less_than("4.3.3", app_version, lteq=True):
        curr_name = new_torrent.files[0].name
        getattr(new_torrent, client_func)(old_path=curr_name,
                                          new_path=name + "_new")
        check(lambda: new_torrent.files[0].name, name + "_new")
Exemplo n.º 13
0
def test_priority(client, new_torrent, client_func):
    disable_queueing(client)

    with pytest.raises(Conflict409Error):
        getattr(new_torrent, client_func[0])()
    with pytest.raises(Conflict409Error):
        getattr(new_torrent, client_func[1])()
    with pytest.raises(Conflict409Error):
        getattr(new_torrent, client_func[2])()
    with pytest.raises(Conflict409Error):
        getattr(new_torrent, client_func[3])()

    enable_queueing(client)
    sleep(2)  # putting sleeps in since these keep crashing qbittorrent

    current_priority = new_torrent.info.priority
    getattr(new_torrent, client_func[0])()
    sleep(1)
    check(lambda: new_torrent.info.priority < current_priority, True)

    current_priority = new_torrent.info.priority
    getattr(new_torrent, client_func[1])()
    sleep(1)
    check(lambda: new_torrent.info.priority > current_priority, True)

    current_priority = new_torrent.info.priority
    getattr(new_torrent, client_func[2])()
    sleep(1)
    check(lambda: new_torrent.info.priority < current_priority, True)

    current_priority = new_torrent.info.priority
    getattr(new_torrent, client_func[3])()
    sleep(1)
    check(lambda: new_torrent.info.priority > current_priority, True)
Exemplo n.º 14
0
def test_add_remove_tags(client, api_version, orig_torrent, client_func, tags):
    if is_version_less_than(api_version, "2.3.0", lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(orig_torrent, client_func[0])(tags=tags)
        with pytest.raises(NotImplementedError):
            getattr(orig_torrent, client_func[1])(tags=tags)
    else:
        getattr(orig_torrent, client_func[0])(tags=tags)
        check(lambda: orig_torrent.info.tags, tags, reverse=True)

        getattr(orig_torrent, client_func[1])(tags=tags)
        check(lambda: orig_torrent.info.tags, tags, reverse=True, negate=True)

        client.torrents_delete_tags(tags=tags)
Exemplo n.º 15
0
def test_upload_limit(orig_torrent, client_func):
    setattr(orig_torrent, client_func[0], 2048)
    check(lambda: getattr(orig_torrent, client_func[0]), 2048)
    check(lambda: orig_torrent.info.up_limit, 2048)

    getattr(orig_torrent, client_func[1])(4096)
    check(lambda: getattr(orig_torrent, client_func[0]), 4096)
    check(lambda: orig_torrent.info.up_limit, 4096)
Exemplo n.º 16
0
def test_edit_tracker(api_version, orig_torrent, client_func):
    if is_version_less_than(api_version, '2.2.0', lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(orig_torrent, client_func)(orig_url='127.0.1.1',
                                               new_url='127.0.1.2')
    else:
        orig_torrent.add_trackers(urls='127.0.1.1')
        getattr(orig_torrent, client_func)(orig_url='127.0.1.1',
                                           new_url='127.0.1.2')
        check(lambda: (t.url for t in orig_torrent.trackers),
              '127.0.1.1',
              reverse=True,
              negate=True)
        check(lambda: (t.url for t in orig_torrent.trackers),
              '127.0.1.2',
              reverse=True)
        getattr(orig_torrent, 'remove_trackers')(urls='127.0.1.2')
Exemplo n.º 17
0
def test_edit_tracker(api_version, orig_torrent, client_func):
    if is_version_less_than(api_version, "2.2.0", lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(orig_torrent, client_func)(
                orig_url="127.0.1.1", new_url="127.0.1.2"
            )
    else:
        orig_torrent.add_trackers(urls="127.0.1.1")
        getattr(orig_torrent, client_func)(orig_url="127.0.1.1", new_url="127.0.1.2")
        check(
            lambda: (t.url for t in orig_torrent.trackers),
            "127.0.1.1",
            reverse=True,
            negate=True,
        )
        check(lambda: (t.url for t in orig_torrent.trackers), "127.0.1.2", reverse=True)
        getattr(orig_torrent, "remove_trackers")(urls="127.0.1.2")
Exemplo n.º 18
0
def test_set_download_path(api_version, new_torrent, client_func):
    if v(api_version) >= v("2.8.4"):
        exp = None
        for attempt in range(2):
            try:
                loc = path.expanduser("~/Downloads/downloadpath3/")
                getattr(new_torrent, client_func)(loc)
                # qBittorrent may return trailing separators depending on version....
                check(
                    lambda: new_torrent.info.download_path,
                    (loc, loc[:len(loc) - 1]),
                    any=True,
                )
                break
            except AssertionError as e:
                exp = e
        if exp:
            raise exp
Exemplo n.º 19
0
def test_rename_folder(api_version, app_version, new_torrent, client_func,
                       name):
    if is_version_less_than(api_version, "2.7", lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(new_torrent, client_func)(old_path="", new_path="")
    # need to ensure we're at least on v4.3.3 to run test
    if is_version_less_than("v4.3.2", app_version, lteq=False):
        # move the file in to a new folder
        orig_file_path = new_torrent.files[0].name
        new_folder = "qwer"
        new_torrent.rename_file(
            old_path=orig_file_path,
            new_path=new_folder + "/" + orig_file_path,
        )
        sleep(1)  # qBittorrent crashes if you make these calls too fast...
        # test rename that new folder
        getattr(new_torrent, client_func)(
            old_path=new_folder,
            new_path=name,
        )
        check(
            lambda: new_torrent.files[0].name.replace("+", " "),
            name + "/" + orig_file_path,
        )
Exemplo n.º 20
0
def test_remove_trackers(api_version, orig_torrent, client_func, trackers):
    if is_version_less_than(api_version, '2.2.0', lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(orig_torrent, client_func)(urls=trackers)
    else:
        check(lambda: (t.url for t in orig_torrent.trackers),
              trackers,
              reverse=True,
              negate=True)
        orig_torrent.add_trackers(urls=trackers)
        check(lambda: (t.url for t in orig_torrent.trackers),
              trackers,
              reverse=True)
        getattr(orig_torrent, client_func)(urls=trackers)
        check(lambda: (t.url for t in orig_torrent.trackers),
              trackers,
              reverse=True,
              negate=True)
Exemplo n.º 21
0
def test_remove_trackers(api_version, orig_torrent, client_func, trackers):
    if v(api_version) < v("2.2.0"):
        with pytest.raises(NotImplementedError):
            getattr(orig_torrent, client_func)(urls=trackers)
    else:
        check(
            lambda: (t.url for t in orig_torrent.trackers),
            trackers,
            reverse=True,
            negate=True,
        )
        orig_torrent.add_trackers(urls=trackers)
        check(lambda: (t.url for t in orig_torrent.trackers),
              trackers,
              reverse=True)
        getattr(orig_torrent, client_func)(urls=trackers)
        check(
            lambda: (t.url for t in orig_torrent.trackers),
            trackers,
            reverse=True,
            negate=True,
        )
Exemplo n.º 22
0
def test_rename(orig_torrent, name):
    orig_torrent.rename(new_name=name)
    check(lambda: orig_torrent.info.name.replace("+", " "), name)
Exemplo n.º 23
0
def test_file_priority(orig_torrent, client_func):
    getattr(orig_torrent, client_func)(file_ids=0, priority=7)
    check(lambda: orig_torrent.files[0].priority, 7)
Exemplo n.º 24
0
def test_add_tracker(new_torrent, client_func, trackers):
    getattr(new_torrent, client_func)(urls=trackers)
    sleep(0.5)  # try to stop crashing qbittorrent
    check(lambda: (t.url for t in new_torrent.trackers),
          trackers,
          reverse=True)
Exemplo n.º 25
0
def test_set_force_start(orig_torrent, client_func):
    current_setting = orig_torrent.force_start
    getattr(orig_torrent, client_func)(enable=(not current_setting))
    check(lambda: orig_torrent.info.force_start, not current_setting)
    getattr(orig_torrent, client_func)(enable=current_setting)
    check(lambda: orig_torrent.info.force_start, current_setting)
Exemplo n.º 26
0
def test_set_auto_management(orig_torrent, client_func):
    current_setting = orig_torrent.auto_tmm
    getattr(orig_torrent, client_func)(enable=(not current_setting))
    check(lambda: orig_torrent.info.auto_tmm, not current_setting)
    getattr(orig_torrent, client_func)(enable=current_setting)
    check(lambda: orig_torrent.info.auto_tmm, current_setting)
Exemplo n.º 27
0
def test_toggle_sequential_download(orig_torrent, client_func):
    current_setting = orig_torrent.seq_dl
    getattr(orig_torrent, client_func)()
    check(lambda: orig_torrent.info.seq_dl, not current_setting)
    getattr(orig_torrent, client_func)()
    check(lambda: orig_torrent.info.seq_dl, current_setting)
Exemplo n.º 28
0
def test_set_super_seeding(orig_torrent, client_func):
    current_setting = orig_torrent.super_seeding
    getattr(orig_torrent, client_func)(enable=(not current_setting))
    check(lambda: orig_torrent.info.super_seeding, not current_setting)
    getattr(orig_torrent, client_func)(enable=current_setting)
    check(lambda: orig_torrent.info.super_seeding, current_setting)