Example #1
0
def test_create_categories(client, api_version, orig_torrent, client_func,
                           save_path, name):
    extra_kwargs = dict(save_path=save_path)
    if is_version_less_than(api_version, "2.1.0",
                            lteq=False) and save_path is not None:
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)(name=name, save_path=save_path)
        extra_kwargs = {}

    try:
        get_func(client, client_func)(name=name, **extra_kwargs)
        client.torrents_set_category(torrent_hashes=orig_torrent.hash,
                                     category=name)
        check(lambda: orig_torrent.info.category.replace("+", " "), name)
        if is_version_less_than("2.1.1", api_version):
            check(
                lambda:
                [n.replace("+", " ") for n in client.torrents_categories()],
                name,
                reverse=True,
            )
            check(
                lambda: (cat.savePath
                         for cat in client.torrents_categories().values()),
                save_path or "",
                reverse=True,
            )
    finally:
        client.torrents_remove_categories(categories=name)
Example #2
0
def test_rename_folder(client, app_version, new_torrent, new_name,
                       client_func):
    if is_version_less_than(app_version, "v4.3.3", lteq=False):
        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 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"
        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,
        )
def test_rename_file(
    client,
    api_version,
    app_version,
    new_torrent,
    new_name,
    client_func,
):
    if is_version_less_than(api_version, "2.4.0", lteq=False):
        with pytest.raises(NotImplementedError):
            getattr(client, client_func)(torrent_hash=new_torrent.hash,
                                         file_id=0,
                                         new_file_name=new_name)
    else:
        getattr(client, client_func)(torrent_hash=new_torrent.hash,
                                     file_id=0,
                                     new_file_name=new_name)
        check(lambda: new_torrent.files[0].name.replace("+", " "), new_name)

        # test invalid file ID is rejected
        with pytest.raises(Conflict409Error):
            getattr(client, client_func)(torrent_hash=new_torrent.hash,
                                         file_id=10,
                                         new_file_name=new_name)

    if is_version_less_than("v4.3.2", app_version, lteq=False):
        getattr(client, client_func)(
            torrent_hash=new_torrent.hash,
            old_path=new_torrent.files[0].name,
            new_path=new_name + "_new",
        )
        check(lambda: new_torrent.files[0].name.replace("+", " "),
              new_name + "_new")
Example #4
0
def test_add_move_refresh_remove_feed(client, api_version, client_func):
    try:
        get_func(client, client_func[0])(item_path=item_one,
                                         url=url)  # rss_add_feed
        check(lambda: get_func(client, client_func[3])(),
              item_one,
              reverse=True)  # rss_items
        get_func(client,
                 client_func[1])(orig_item_path=item_one,
                                 new_item_path=item_two)  # rss_move_item
        check(lambda: get_func(client, client_func[3])(),
              item_two,
              reverse=True)  # rss_items

        # update item_two
        if is_version_less_than(api_version, '2.2', lteq=False):
            with pytest.raises(NotImplementedError):
                get_func(client, client_func[2])(
                    item_path=item_two)  # rss_refresh_item
        else:
            get_func(client,
                     client_func[2])(item_path=item_two)  # rss_refresh_item

        items = get_func(client,
                         client_func[3])(include_feed_data=True)  # rss_items
        assert isinstance(items, RSSitemsDictionary)
        try:
            items = getattr(get_func(client, client_func[3]),
                            'without_data')  # rss_items
            assert isinstance(items, RSSitemsDictionary)
            items = getattr(get_func(client, client_func[3]),
                            'with_data')  # rss_items
            assert isinstance(items, RSSitemsDictionary)
        except AttributeError:
            pass

        if is_version_less_than(api_version, '2.5.1', lteq=False):
            with pytest.raises(NotImplementedError):
                get_func(client, client_func[4])()  # rss_mark_as_read
        else:
            check(lambda: client.rss_items(), item_two, reverse=True)
            check(lambda: client.rss_items(include_feed_data=True)[item_two],
                  'articles',
                  reverse=True)
            items = client.rss_items(include_feed_data=True)  # rss_items
            if items[item_two]['articles']:
                get_func(client,
                         client_func[4])(item_path=item_two,
                                         article_id=items[item_two]['articles']
                                         [0])  # rss_mark_as_read
    finally:
        get_func(client, client_func[5])(item_path=item_two)  # rss_remove_item
        check(lambda: get_func(client, client_func[3])(),
              item_two,
              reverse=True,
              negate=True)  # rss_items
Example #5
0
def test_categories(client, api_version, client_func):
    if is_version_less_than(api_version, "2.1.1",
                            lteq=False) or is_version_less_than(
                                "2.6", api_version, lteq=True):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)()
    else:
        check(lambda: get_func(client, client_func)(),
              "All categories",
              reverse=True)
Example #6
0
def test_set_location(client, api_version, client_func, new_torrent):
    if is_version_less_than("2.0.1", api_version, lteq=False):
        home = path.expanduser("~")
        # whether the location is writable is only checked after version 2.0.1
        if is_version_less_than("2.0.1", api_version, lteq=False):
            with pytest.raises(Forbidden403Error):
                get_func(client, client_func)(location="/etc/",
                                              torrent_hashes=new_torrent.hash)

        get_func(client, client_func)(location="%s/Downloads/1/" % home,
                                      torrent_hashes=new_torrent.hash)
        check(lambda: new_torrent.info.save_path, "%s/Downloads/1/" % home)
Example #7
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")
Example #8
0
def test_rules(client, api_version, client_func):
    def check_for_rule(name):
        try:
            get_func(client, client_func[2])()  # rss_rules
            check(
                lambda: get_func(client, client_func[2])(), name, reverse=True
            )  # rss_rules
        except TypeError:
            check(
                lambda: get_func(client, client_func[2]), name, reverse=True
            )  # rss_rules

    rule_name = item_one + "Rule"
    rule_name_new = rule_name + "New"
    rule_def = {"enabled": True, "affectedFeeds": url, "addPaused": True}
    try:
        get_func(client, client_func[0])(item_path=item_one, url=url)  # rss_add_feed
        if is_version_less_than(api_version, "2.2", lteq=False):
            with pytest.raises(NotImplementedError):
                client.rss.refresh_item(item_path=item_two)
        else:
            client.rss.refresh_item(item_path=item_two)
        get_func(client, client_func[1])(
            rule_name=rule_name, rule_def=rule_def
        )  # rss_set_rule
        check_for_rule(rule_name)

        if is_version_less_than(
            "2.6", api_version, lteq=True
        ):  # rename was broken in qBittorrent for a period
            get_func(client, client_func[3])(
                orig_rule_name=rule_name, new_rule_name=rule_name_new
            )  # rss_rename_rule
            check_for_rule(rule_name_new)
        if is_version_less_than(api_version, "2.5.1", lteq=False):
            with pytest.raises(NotImplementedError):
                get_func(client, client_func[4])(
                    rule_name=rule_name
                )  # rss_matching_articles
        else:
            assert isinstance(
                get_func(client, client_func[4])(rule_name=rule_name),
                RSSitemsDictionary,
            )  # rss_matching_articles
    finally:
        get_func(client, client_func[5])(rule_name=rule_name)  # rss_remove_rule
        get_func(client, client_func[5])(rule_name=rule_name_new)  # rss_remove_rule
        check(lambda: client.rss_rules(), rule_name, reverse=True, negate=True)
        get_func(client, client_func[6])(item_path=item_one)  # rss_remove_item
        assert item_two not in client.rss_items()
        check(lambda: client.rss_items(), item_two, reverse=True, negate=True)
Example #9
0
def test_enable_plugin(client, api_version, client_func):
    if is_version_less_than(api_version, "2.1.1", lteq=False):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func[1])()
    else:
        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,
        )
Example #10
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 is_version_less_than(api_version, "2.0.1", lteq=False):
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)(torrent_hashes=orig_torrent_hash)
Example #11
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)
Example #12
0
def test_search(client, api_version, client_func):
    if is_version_less_than(api_version, "2.1.1", lteq=False):
        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
Example #13
0
def test_toggle_first_last_piece_priority(client, api_version, client_func,
                                          new_torrent):
    if is_version_less_than("2.0.0", api_version, lteq=False):
        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)
Example #14
0
def test_categories1(client, api_version):
    if is_version_less_than(api_version, "2.1.1", lteq=False):
        with pytest.raises(NotImplementedError):
            client.torrents_categories()
    else:
        assert isinstance(client.torrents_categories(),
                          TorrentCategoriesDictionary)
Example #15
0
def test_install_uninstall_plugin(client, api_version, client_func):
    if is_version_less_than(api_version, "2.1.1", lteq=False):
        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
Example #16
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)
Example #17
0
def test_delete_tags(client, api_version, client_func, tags):
    if is_version_less_than(api_version, "2.3.0", lteq=False):
        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)
Example #18
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)
Example #19
0
def test_request_http400(client, api_version, orig_torrent_hash):
    with pytest.raises(MissingRequiredParameters400Error):
        client.torrents_file_priority(hash=orig_torrent_hash)

    if is_version_less_than("4.1.5", api_version, lteq=False):
        with pytest.raises(InvalidRequest400Error):
            client.torrents_file_priority(
                hash=orig_torrent_hash, file_ids="asdf", priority="asdf"
            )
Example #20
0
def test_tags(client, api_version, client_func):
    if is_version_less_than(api_version, "2.3.0", lteq=False):
        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)
Example #21
0
def test_refresh_item(client, api_version, rss_feed):
    if is_version_less_than(api_version, "2.2", lteq=False):
        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,
        )
        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,
        )

    if is_version_less_than(api_version, "2.2", lteq=False):
        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,
        )
        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,
        )
Example #22
0
def test_add_tag_though_property(client, api_version):
    name = "newtag"
    if is_version_less_than(api_version, "2.3.0", lteq=False):
        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
Example #23
0
def test_add_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):
            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)
Example #24
0
def test_build_info(client, api_version):
    def run_tests():
        assert 'libtorrent' in client.app_build_info()
        assert 'libtorrent' in client.app.build_info

    if is_version_less_than(api_version, '2.3', lteq=False):
        with pytest.raises(NotImplementedError):
            run_tests()
    else:
        run_tests()
Example #25
0
def test_categories2(client, api_version):
    if is_version_less_than(api_version, "2.1.1", lteq=False):
        with pytest.raises(NotImplementedError):
            client.torrent_categories.categories
    else:
        name = "new_category"
        client.torrent_categories.categories = {"name": name, "savePath": "/tmp"}
        assert name in client.torrent_categories.categories
        client.torrent_categories.categories = {"name": name, "savePath": "/tmp/new"}
        assert client.torrent_categories.categories[name]["savePath"] == "/tmp/new"
        client.torrents_remove_categories(categories=name)
Example #26
0
def test_delete(client, api_version):
    if is_version_less_than(api_version, "2.1.1", lteq=False):
        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()
Example #27
0
def test_edit_category(client, api_version, client_func, save_path, name):
    if is_version_less_than(api_version, '2.1.0',
                            lteq=False) and save_path is not None:
        with pytest.raises(NotImplementedError):
            get_func(client, client_func)(name=name, save_path=save_path)

    if is_version_less_than('2.1.1', api_version):
        try:
            client.torrents_create_category(name=name, save_path='/tmp/tmp')
            get_func(client, client_func)(name=name, save_path=save_path)
            check(lambda:
                  [n.replace('+', ' ') for n in client.torrents_categories()],
                  name,
                  reverse=True)
            check(lambda: (cat.savePath
                           for cat in client.torrents_categories().values()),
                  save_path or '',
                  reverse=True)
        finally:
            client.torrents_remove_categories(categories=name)
Example #28
0
def test_add_options(api_version, new_torrent):
    check(lambda: new_torrent.category, 'test_category')
    check(lambda: new_torrent.state, ('pausedDL', 'checkingResumeData'),
          reverse=True,
          any=True)
    check(lambda: new_torrent.save_path, path.expanduser('~/test_download/'))
    check(lambda: new_torrent.up_limit, 1024)
    check(lambda: new_torrent.dl_limit, 2048)
    check(lambda: new_torrent.seq_dl, True)
    if is_version_less_than('2.0.0', api_version, lteq=False):
        check(lambda: new_torrent.f_l_piece_prio, True)
Example #29
0
def test_update_plugins(client, api_version, client_func):
    if is_version_less_than(api_version, '2.1.1', lteq=False):
        with pytest.raises(NotImplementedError):
            client.search_update_plugins()
    else:
        client.search.update_plugins()
        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)
Example #30
0
def test_rules(client, api_version, client_func):
    rule_name = item_one + 'Rule'
    rule_name_new = rule_name + 'New'
    rule_def = {'enabled': True, 'affectedFeeds': url, 'addPaused': True}
    try:
        get_func(client, client_func[0])(item_path=item_one,
                                         url=url)  # rss_add_feed
        if is_version_less_than(api_version, '2.2', lteq=False):
            with pytest.raises(NotImplementedError):
                client.rss.refresh_item(item_path=item_two)
        else:
            client.rss.refresh_item(item_path=item_two)
        get_func(client, client_func[1])(rule_name=rule_name,
                                         rule_def=rule_def)  # rss_set_rule
        try:
            get_func(client, client_func[2])()  # rss_rules
            check(lambda: get_func(client, client_func[2])(),
                  rule_name,
                  reverse=True)  # rss_rules
        except TypeError:
            check(lambda: get_func(client, client_func[2]),
                  rule_name,
                  reverse=True)  # rss_rules
        # rename is broken https://github.com/qbittorrent/qBittorrent/issues/12558
        # get_func(client, client_func[3])(orig_rule_name=rule_name, new_rule_name=rule_name_new)
        # check(get_func(client, client_func[2]), rule_name_new, reverse=True)
        if is_version_less_than(api_version, '2.5.1', lteq=False):
            with pytest.raises(NotImplementedError):
                get_func(client, client_func[4])(
                    rule_name=rule_name)  # rss_matching_articles
        else:
            assert isinstance(
                get_func(client, client_func[4])(rule_name=rule_name),
                RSSitemsDictionary)  # rss_matching_articles
    finally:
        get_func(client,
                 client_func[5])(rule_name=rule_name)  # rss_remove_rule
        check(lambda: client.rss_rules(), rule_name, reverse=True, negate=True)
        get_func(client, client_func[6])(item_path=item_one)  # rss_remove_item
        assert item_two not in client.rss_items()
        check(lambda: client.rss_items(), item_two, reverse=True, negate=True)