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")
示例#2
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)
示例#3
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
示例#4
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
示例#5
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,
        )
示例#6
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
示例#7
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)
示例#8
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,
        )
示例#9
0
def test_upload_limit(client, client_func, orig_torrent):
    orig_upload_limit = get_func(
        client,
        client_func[1])(torrent_hashes=orig_torrent.hash)[orig_torrent.hash]

    get_func(client, client_func[0])(torrent_hashes=orig_torrent.hash,
                                     limit=100)
    assert isinstance(
        get_func(client, client_func[1])(torrent_hashes=orig_torrent.hash),
        TorrentLimitsDictionary,
    )
    check(
        lambda: get_func(client, client_func[1])
        (torrent_hashes=orig_torrent.hash)[orig_torrent.hash],
        100,
    )

    # reset upload limit
    get_func(client, client_func[0])(torrent_hashes=orig_torrent.hash,
                                     limit=orig_upload_limit)
    check(
        lambda: get_func(client, client_func[1])
        (torrent_hashes=orig_torrent.hash)[orig_torrent.hash],
        orig_upload_limit,
    )
示例#10
0
def test_categories(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)()
    else:
        check(lambda: get_func(client, client_func)(),
              'All categories',
              reverse=True)
示例#11
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)
示例#12
0
def test_move(client, rss_feed):
    new_name = "new_loc"

    client.rss_move_item(orig_item_path=rss_feed, new_item_path=new_name)
    check(lambda: client.rss_items(), new_name, reverse=True)

    client.rss.move_item(orig_item_path=new_name, new_item_path=rss_feed)
    check(lambda: client.rss.items(), rss_feed, reverse=True)
示例#13
0
def test_torrents_set_auto_management(client, client_func, orig_torrent):
    current_setting = orig_torrent.info.auto_tmm
    get_func(client, client_func)(enable=(not current_setting),
                                  torrent_hashes=orig_torrent.hash)
    check(lambda: orig_torrent.info.auto_tmm, (not current_setting))
    get_func(client,
             client_func)(enable=False,
                          torrent_hashes=orig_torrent.hash)  # leave on False
示例#14
0
def test_add_remove_folder(client, client_func):
    get_func(client, client_func[0])(folder_path=folder_one)  # rss_add_folder
    check(lambda: client.rss_items(), folder_one, reverse=True)
    get_func(client, client_func[1])(item_path=folder_one)  # rss_remove_item
    check(lambda: get_func(client, client_func[2])(),
          folder_one,
          reverse=True,
          negate=True)  # rss_items
示例#15
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)
示例#16
0
 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
示例#17
0
 def delete():
     get_func(client, client_func[1])(delete_files=True,
                                      torrent_hashes=torrent1_hash)
     get_func(client, client_func[1])(delete_files=True,
                                      torrent_hashes=torrent2_hash)
     check(lambda: [t.hash for t in client.torrents_info()],
           torrent2_hash,
           reverse=True,
           negate=True)
示例#18
0
def test_file_priority(client, orig_torrent, orig_torrent_hash, client_func):
    get_func(client, client_func)(torrent_hash=orig_torrent_hash,
                                  file_ids=0,
                                  priority=6)
    check(lambda: orig_torrent.files[0].priority, 6)
    get_func(client, client_func)(torrent_hash=orig_torrent_hash,
                                  file_ids=0,
                                  priority=7)
    check(lambda: orig_torrent.files[0].priority, 7)
示例#19
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
示例#20
0
def test_create_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:
        try:
            get_func(client, client_func)(tags=tags)
            check(lambda: client.torrents_tags(), tags, reverse=True)
        finally:
            client.torrents_delete_tags(tags=tags)
示例#21
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)
示例#22
0
def test_pause_resume(client, orig_torrent, orig_torrent_hash, client_func):
    get_func(client, client_func[0])(torrent_hashes=orig_torrent_hash)
    check(lambda: client.torrents_info(torrents_hashes=orig_torrent.hash)[0].
          state, ('stalledDL', 'pausedDL'),
          any=True)

    get_func(client, client_func[1])(torrent_hashes=orig_torrent_hash)
    check(lambda: client.torrents_info(torrents_hashes=orig_torrent.hash)[0].
          state,
          'pausedDL',
          negate=True)
示例#23
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)
示例#24
0
def test_action_for_all_torrents(client):
    client.torrents.resume.all()
    for torrent in client.torrents.info():
        check(lambda: client.torrents_info(torrents_hashes=torrent.hash)[0].
              state, ('pausedDL', ),
              negate=True)
    client.torrents.pause.all()
    for torrent in client.torrents.info():
        check(lambda: client.torrents_info(torrents_hashes=torrent.hash)[0].
              state, ('stalledDL', 'pausedDL'),
              any=True)
示例#25
0
def test_set_category(client, client_func, name, orig_torrent):
    with pytest.raises(Conflict409Error):
        get_func(client, client_func)(category="/!@#$%^&*(",
                                      torrent_hashes=orig_torrent.hash)

    client.torrents_create_category(name=name)
    try:
        get_func(client, client_func)(category=name,
                                      torrent_hashes=orig_torrent.hash)
        check(lambda: orig_torrent.info.category.replace("+", " "), name)
    finally:
        client.torrents_remove_categories(categories=name)
示例#26
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)
示例#27
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)
示例#28
0
 def inner():
     try:
         f()
         check(lambda: [t.hash for t in client.torrents_info()],
               torrent1_hash,
               reverse=True)
         check(lambda: [t.hash for t in client.torrents_info()],
               torrent2_hash,
               reverse=True)
     finally:
         sleep(1)
         delete()
示例#29
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 is_version_less_than("2.1.1", api_version):
        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)
示例#30
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,
        )