Esempio n. 1
0
def test_rename_folder(client, app_version, new_torrent, new_name,
                       client_func):
    if v(app_version) < v("v4.3.3"):
        with pytest.raises(NotImplementedError):
            getattr(client, client_func)(torrent_hash="asdf",
                                         old_path="asdf",
                                         new_path="zxcv")
    # need to ensure we're at least on v4.3.3 to run test
    if v(app_version) >= v("v4.3.3"):
        # move the file in to a new folder
        orig_file_path = new_torrent.files[0].name
        new_folder = "qwer"
        client.torrents_rename_file(
            torrent_hash=new_torrent.hash,
            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(client, client_func)(
            torrent_hash=new_torrent.hash,
            old_path=new_folder,
            new_path=new_name,
        )
        check(
            lambda: new_torrent.files[0].name.replace("+", " "),
            new_name + "/" + orig_file_path,
        )
Esempio n. 2
0
def test_search(client, api_version, client_func):
    if v(api_version) < v("2.1.1"):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func[0])()
    else:
        job = get_func(client, client_func[0])(pattern="Ubuntu",
                                               plugins="enabled",
                                               category="all")
        assert isinstance(job, SearchJobDictionary)
        statuses = get_func(client, client_func[1])(search_id=job["id"])
        assert isinstance(statuses, SearchStatusesList)
        assert statuses[0]["status"] == "Running"
        results = get_func(client, client_func[2])(search_id=job["id"],
                                                   limit=1)
        assert isinstance(results, SearchResultsDictionary)
        results = job.results()
        assert isinstance(results, SearchResultsDictionary)
        get_func(client, client_func[3])(search_id=job["id"])
        check(
            lambda: get_func(client, client_func[1])
            (search_id=job["id"])[0]["status"],
            "Stopped",
        )
        get_func(client, client_func[4])(search_id=job["id"])
        statuses = get_func(client, client_func[1])()
        assert not statuses
Esempio n. 3
0
def test_toggle_first_last_piece_priority(client, api_version, client_func,
                                          new_torrent):
    if v(api_version) > v("2.0.0"):
        current_setting = new_torrent.info.f_l_piece_prio
        sleep(1)
        get_func(client, client_func)(torrent_hashes=new_torrent.hash)
        check(lambda: new_torrent.info.f_l_piece_prio, not current_setting)
Esempio n. 4
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)
Esempio n. 5
0
def _categories_save_path_key(api_version):
    """
    With qBittorrent 4.4.0 (Web API 2.8.4), the key in the category
    definition returned changed from savePath to save_path....
    """
    return "save_path" if v("2.8.5") > v(api_version) >= v(
        "2.8.4") else "savePath"
Esempio n. 6
0
def test_categories1(client, api_version):
    if v(api_version) < v("2.1.1"):
        with pytest.raises(NotImplementedError):
            client.torrents_categories()
    else:
        assert isinstance(client.torrents_categories(),
                          TorrentCategoriesDictionary)
Esempio n. 7
0
def test_enable_plugin(client, api_version, client_func):
    if v(api_version) < v("2.1.1"):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func[1])()
    else:
        loop_limit = 3
        for loop_count in range(loop_limit):
            try:
                try:
                    plugins = get_func(client, client_func[0])()
                except TypeError:
                    plugins = get_func(client, client_func[0])
                get_func(client,
                         client_func[1])(plugins=(p["name"] for p in plugins),
                                         enable=False)
                check(
                    lambda: (p["enabled"] for p in client.search_plugins()),
                    True,
                    reverse=True,
                    negate=True,
                )
                get_func(client,
                         client_func[1])(plugins=(p["name"] for p in plugins),
                                         enable=True)
                check(
                    lambda: (p["enabled"] for p in client.search_plugins()),
                    False,
                    reverse=True,
                    negate=True,
                )
                break
            except Exception as e:
                if loop_count >= (loop_limit - 1):
                    raise e
Esempio n. 8
0
def test_install_uninstall_plugin(client, api_version, client_func):
    if v(api_version) < v("2.1.1"):
        with pytest.raises(NotImplementedError):
            client.search_install_plugin()
        with pytest.raises(NotImplementedError):
            client.search_uninstall_plugin()
    else:
        for _ in range(3):
            try:
                get_func(client, client_func[0])(sources=legit_torrents_url)
                check(
                    lambda: (p.name for p in client.search.plugins),
                    plugin_name,
                    reverse=True,
                )
                break
            except AssertionError:
                pass
        for _ in range(3):
            try:
                get_func(client, client_func[1])(names=plugin_name)
                check(
                    lambda: (p.name for p in client.search.plugins),
                    plugin_name,
                    reverse=True,
                    negate=True,
                )
            except AssertionError:
                pass
Esempio n. 9
0
def test_torrents_info(client, api_version, orig_torrent_hash, client_func):
    assert isinstance(get_func(client, client_func)(), TorrentInfoList)
    if "." in client_func:
        assert isinstance(get_func(client, client_func).all(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).downloading(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).completed(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).paused(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).active(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).inactive(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).resumed(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).stalled(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).stalled_uploading(), TorrentInfoList)
        assert isinstance(
            get_func(client, client_func).stalled_downloading(),
            TorrentInfoList)

    if v(api_version) < v("2.0.1"):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)(torrent_hashes=orig_torrent_hash)
Esempio n. 10
0
def test_delete_tags(client, api_version, client_func, tags):
    if v(api_version) < v("2.3.0"):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)(tags=tags)
    else:
        client.torrents_create_tags(tags=tags)
        get_func(client, client_func)(tags=tags)
        check(lambda: client.torrents_tags(), tags, reverse=True, negate=True)
Esempio n. 11
0
def test_categories(client, api_version, client_func):
    if v(api_version) < v("2.1.1") or v(api_version) >= v("2.6"):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)()
    else:
        check(lambda: get_func(client, client_func)(),
              "All categories",
              reverse=True)
Esempio n. 12
0
def test_torrents_info_tag(client, api_version, new_torrent, client_func):
    if v(api_version) < v("2.8.3"):
        return
    tag_name = "tag_filter_name"
    client.torrents_add_tags(tags=tag_name, torrent_hashes=new_torrent.hash)
    torrents = get_func(client, client_func)(torrent_hashes=new_torrent.hash,
                                             tag=tag_name)
    assert new_torrent.hash in {t.hash for t in torrents}
Esempio n. 13
0
def test_tags(client, api_version, client_func):
    if v(api_version) < v("2.3.0"):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)()
    else:
        try:
            assert isinstance(get_func(client, client_func)(), TagList)
        except:
            assert isinstance(get_func(client, client_func), TagList)
Esempio n. 14
0
def test_build_info(client, api_version):
    if v(api_version) >= v("2.3"):
        assert "libtorrent" in client.app_build_info()
        assert "libtorrent" in client.app.build_info
    else:
        with pytest.raises(NotImplementedError):
            assert "libtorrent" in client.app_build_info()
        with pytest.raises(NotImplementedError):
            assert "libtorrent" in client.app.build_info
Esempio n. 15
0
def test_http400(client, app_version, orig_torrent_hash):
    with pytest.raises(exceptions.MissingRequiredParameters400Error):
        client.torrents_file_priority(hash=orig_torrent_hash)

    if v(app_version) > v("4.1.5"):
        with pytest.raises(exceptions.InvalidRequest400Error):
            client.torrents_file_priority(hash=orig_torrent_hash,
                                          file_ids="asdf",
                                          priority="asdf")
Esempio n. 16
0
def test_set_share_limits(api_version, orig_torrent, client_func):
    if v(api_version) < v("2.0.1"):
        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)
Esempio n. 17
0
def test_add_tag_though_property(client, api_version):
    name = "newtag"
    if v(api_version) < v("2.3.0"):
        with pytest.raises(NotImplementedError):
            client.torrent_tags.tags = name
    else:
        client.torrent_tags.tags = name
        assert name in client.torrent_tags.tags
        client.torrent_tags.delete_tags(name)
        assert name not in client.torrent_tags.tags
Esempio n. 18
0
def test_delete(client, api_version):
    if v(api_version) < v("2.1.1"):
        with pytest.raises(NotImplementedError):
            client.search_stop(search_id=100)
    else:
        job = client.search_start(pattern="Ubuntu",
                                  plugins="enabled",
                                  category="all")
        job.delete()
        with pytest.raises(NotFound404Error):
            job.status()
Esempio n. 19
0
def test_add_tags(client, api_version, orig_torrent, client_func, tags):
    if v(api_version) < v("2.3.0"):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)(tags=tags,
                                          torrent_hashes=orig_torrent.hash)
    else:
        try:
            get_func(client, client_func)(tags=tags,
                                          torrent_hashes=orig_torrent.hash)
            check(lambda: orig_torrent.info.tags, tags, reverse=True)
        finally:
            client.torrents_delete_tags(tags=tags)
Esempio n. 20
0
def test_set_location(client, api_version, client_func, new_torrent):
    if v(api_version) > v("2.0.1"):
        with pytest.raises(Forbidden403Error):
            get_func(client, client_func)(location="/etc/",
                                          torrent_hashes=new_torrent.hash)

        loc = path.expanduser("~/Downloads/1/")
        get_func(client, client_func)(location=loc,
                                      torrent_hashes=new_torrent.hash)
        # qBittorrent may return trailing separators depending on version....
        check(lambda: new_torrent.info.save_path, (loc, loc[:len(loc) - 1]),
              any=True)
Esempio n. 21
0
        def wrapper(client, *args, **kwargs):

            # if the endpoint doesn't exist, return None or log an error / raise an Exception
            if v(client.app_web_api_version()) >= v(version_obsoleted):
                error_message = ("ERROR: Endpoint '%s' is Not Implemented. "
                                 "This endpoint was removed in Web API v%s." %
                                 (endpoint, version_obsoleted))
                _check_for_raise(client=client, error_message=error_message)
                return None

            # send request to endpoint
            return func(client, *args, **kwargs)
Esempio n. 22
0
        def wrapper(client, *args, **kwargs):

            # if the endpoint doesn't exist, return None or log an error / raise an Exception
            if v(client.app_web_api_version()) < v(version_introduced):
                error_message = (
                    "ERROR: Endpoint '%s' is Not Implemented in this version of qBittorrent. "
                    "This endpoint is available starting in Web API v%s." %
                    (endpoint, version_introduced))
                _check_for_raise(client=client, error_message=error_message)
                return None

            # send request to endpoint
            return func(client, *args, **kwargs)
Esempio n. 23
0
def test_update_plugins(client, api_version, client_func):
    if v(api_version) < v("2.1.1"):
        with pytest.raises(NotImplementedError):
            client.search_update_plugins()
    else:
        get_func(client, client_func)()
        check(
            lambda: any(entry["message"].startswith("Updating plugin "
                                                    ) or entry["message"] ==
                        "All plugins are already up to date."
                        for entry in reversed(client.log.main())),
            True,
        )
Esempio n. 24
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")
Esempio n. 25
0
    def rss_refresh_item(self, item_path=None, **kwargs):
        """
        Trigger a refresh for a RSS item (alias: rss_refreshItem)

        :param item_path: path to item to be refreshed (e.g. Folder\\Subfolder\\ItemName)
        :return: None
        """
        # HACK: v4.1.7 and v4.1.8 both use api v2.2; however, refreshItem was introduced in v4.1.8
        if v(self.app_version()) > v("v4.1.7"):
            data = {"itemPath": item_path}
            self._post(_name=APINames.RSS,
                       _method="refreshItem",
                       data=data,
                       **kwargs)
Esempio n. 26
0
def test_add_remove_tags(client, api_version, orig_torrent, client_func, tags):
    if v(api_version) < v("2.3.0"):
        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)
Esempio n. 27
0
def test_remove_category(client, api_version, orig_torrent, client_func,
                         categories):
    for name in categories:
        client.torrents_create_category(name=name)
    orig_torrent.set_category(category=categories[0])
    get_func(client, client_func)(categories=categories)
    if v(api_version) > v("2.1.1"):
        check(
            lambda:
            [n.replace("+", " ") for n in client.torrents_categories()],
            categories,
            reverse=True,
            negate=True,
        )
    check(lambda: orig_torrent.info.category, categories[0], negate=True)
Esempio n. 28
0
def test_refresh_item(client, api_version, rss_feed):
    if v(api_version) < v("2.2"):
        with pytest.raises(NotImplementedError):
            client.rss_refresh_item(item_path=rss_feed)
    else:
        client.rss_refresh_item(item_path=rss_feed)
        check(
            lambda: client.rss_items(include_feed_data=True)[rss_feed][
                "lastBuildDate"],
            "",
            negate=True,
            check_limit=20,
        )
        last_refresh = client.rss_items(
            include_feed_data=True)[rss_feed]["lastBuildDate"]
        sleep(1)
        client.rss_refresh_item(item_path=rss_feed)
        check(
            lambda: client.rss_items(include_feed_data=True)[rss_feed][
                "lastBuildDate"],
            last_refresh,
            negate=True,
            check_limit=20,
        )

    if v(api_version) < v("2.2"):
        with pytest.raises(NotImplementedError):
            client.rss.refresh_item(item_path=rss_feed)
    else:
        client.rss.refresh_item(item_path=rss_feed)
        check(
            lambda: client.rss_items(include_feed_data=True)[rss_feed][
                "lastBuildDate"],
            "",
            negate=True,
            check_limit=20,
        )
        last_refresh = client.rss_items(
            include_feed_data=True)[rss_feed]["lastBuildDate"]
        sleep(1)
        client.rss.refresh_item(item_path=rss_feed)
        check(
            lambda: client.rss_items(include_feed_data=True)[rss_feed][
                "lastBuildDate"],
            last_refresh,
            negate=True,
            check_limit=20,
        )
Esempio n. 29
0
def test_ban_peers(client, api_version):
    if v(api_version) < v("2.3"):
        with pytest.raises(NotImplementedError):
            client.transfer_ban_peers(peers="1.1.1.1:8080")
    else:
        client.transfer_ban_peers(peers="1.1.1.1:8080")
        assert "1.1.1.1" in client.app.preferences.banned_IPs
        client.transfer.ban_peers(peers="1.1.1.2:8080")
        assert "1.1.1.2" in client.app.preferences.banned_IPs

        client.transfer_ban_peers(peers=["1.1.1.3:8080", "1.1.1.4:8080"])
        assert "1.1.1.3" in client.app.preferences.banned_IPs
        assert "1.1.1.4" in client.app.preferences.banned_IPs
        client.transfer.ban_peers(peers=["1.1.1.5:8080", "1.1.1.6:8080"])
        assert "1.1.1.5" in client.app.preferences.banned_IPs
        assert "1.1.1.6" in client.app.preferences.banned_IPs
Esempio n. 30
0
def test_remove_trackers(client, api_version, trackers, client_func,
                         orig_torrent):
    if v(api_version) < v("2.2.0"):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)(torrent_hash=orig_torrent.hash,
                                          urls=trackers)
    else:
        orig_torrent.add_trackers(trackers)
        get_func(client, client_func)(torrent_hash=orig_torrent.hash,
                                      urls=trackers)
        check(
            lambda: (t.url for t in orig_torrent.trackers),
            trackers,
            reverse=True,
            negate=True,
        )