Example #1
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)
Example #2
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
Example #3
0
    def add_by_url(single):
        urls = (torrent1_url, torrent2_url)

        if single:
            get_func(client, client_func[0])(urls=urls[0])
        else:
            get_func(client, client_func[0])(urls=urls)
Example #4
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 #5
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 #6
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
Example #7
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
Example #8
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)
Example #9
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 #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)
Example #11
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 #12
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)
Example #13
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
Example #14
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)
Example #15
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)
Example #16
0
    def add_by_filename(single):
        download_file(url=torrent1_url, filename=torrent1_filename)
        download_file(url=torrent2_url, filename=torrent2_filename)
        files = ("~/%s" % torrent1_filename, "~/%s" % torrent2_filename)

        if single:
            assert get_func(client, client_func[0])(torrent_files=files[0]) == "Ok."
        else:
            assert get_func(client, client_func[0])(torrent_files=files) == "Ok."
Example #17
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 #18
0
    def add_by_bytes(single):
        files = (
            download_file(torrent1_url, return_bytes=True),
            download_file(torrent2_url, return_bytes=True),
        )

        if single:
            assert get_func(client, client_func[0])(torrent_files=files[0]) == "Ok."
        else:
            assert get_func(client, client_func[0])(torrent_files=files) == "Ok."
Example #19
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)
Example #20
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)
Example #21
0
    def add_by_filehandles(single):
        download_file(url=torrent1_url, filename=torrent1_filename)
        download_file(url=torrent2_url, filename=torrent2_filename)
        files = (
            open(path.expanduser("~/" + torrent1_filename), "rb"),
            open(path.expanduser("~/" + torrent2_filename), "rb"),
        )

        if single:
            assert get_func(client, client_func[0])(torrent_files=files[0]) == "Ok."
        else:
            assert get_func(client, client_func[0])(torrent_files=files) == "Ok."
Example #22
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)
Example #23
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 #24
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)
Example #25
0
def test_remove_trackers(client, api_version, trackers, client_func, orig_torrent):
    if is_version_less_than(api_version, "2.2.0", lteq=False):
        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,
        )
Example #26
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)
Example #27
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,
        )
Example #28
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 #29
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,
    )
Example #30
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