Skip to content

Commit

Permalink
Add "individual torrent" methods to torrents namespace (fixes #261)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmartin16 committed Oct 18, 2023
1 parent 79fae7f commit 0a06370
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 37 deletions.
175 changes: 175 additions & 0 deletions src/qbittorrentapi/torrents.py
Original file line number Diff line number Diff line change
Expand Up @@ -2697,6 +2697,181 @@ def errored(
**kwargs,
)

@wraps(TorrentsAPIMixIn.torrents_properties)
def properties(
self,
torrent_hash: str | None = None,
**kwargs: APIKwargsT,
) -> TorrentPropertiesDictionary:
return self._client.torrents_properties(torrent_hash=torrent_hash, **kwargs)

@wraps(TorrentsAPIMixIn.torrents_trackers)
def trackers(
self,
torrent_hash: str | None = None,
**kwargs: APIKwargsT,
) -> TrackersList:
return self._client.torrents_trackers(torrent_hash=torrent_hash, **kwargs)

@wraps(TorrentsAPIMixIn.torrents_webseeds)
def webseeds(
self,
torrent_hash: str | None = None,
**kwargs: APIKwargsT,
) -> WebSeedsList:
return self._client.torrents_webseeds(torrent_hash=torrent_hash, **kwargs)

@wraps(TorrentsAPIMixIn.torrents_files)
def files(
self,
torrent_hash: str | None = None,
**kwargs: APIKwargsT,
) -> TorrentFilesList:
return self._client.torrents_files(torrent_hash=torrent_hash, **kwargs)

@wraps(TorrentsAPIMixIn.torrents_piece_states)
def piece_states(
self,
torrent_hash: str | None = None,
**kwargs: APIKwargsT,
) -> TorrentPieceInfoList:
return self._client.torrents_piece_states(torrent_hash=torrent_hash, **kwargs)

pieceStates = piece_states

@wraps(TorrentsAPIMixIn.torrents_piece_hashes)
def piece_hashes(
self,
torrent_hash: str | None = None,
**kwargs: APIKwargsT,
) -> TorrentPieceInfoList:
return self._client.torrents_piece_hashes(torrent_hash=torrent_hash, **kwargs)

pieceHashes = piece_hashes

@wraps(TorrentsAPIMixIn.torrents_add_trackers)
def add_trackers(
self,
torrent_hash: str | None = None,
urls: Iterable[str] | None = None,
**kwargs: APIKwargsT,
) -> None:
return self._client.torrents_add_trackers(
torrent_hash=torrent_hash,
urls=urls,
**kwargs,
)

addTrackers = add_trackers

@wraps(TorrentsAPIMixIn.torrents_edit_tracker)
def edit_tracker(
self,
torrent_hash: str | None = None,
original_url: str | None = None,
new_url: str | None = None,
**kwargs: APIKwargsT,
) -> None:
return self._client.torrents_edit_tracker(
torrent_hash=torrent_hash,
original_url=original_url,
new_url=new_url,
**kwargs,
)

editTracker = edit_tracker

@wraps(TorrentsAPIMixIn.torrents_remove_trackers)
def remove_trackers(
self,
torrent_hash: str | None = None,
urls: Iterable[str] | None = None,
**kwargs: APIKwargsT,
) -> None:
return self._client.torrents_remove_trackers(
torrent_hash=torrent_hash,
urls=urls,
**kwargs,
)

removeTrackers = remove_trackers

@wraps(TorrentsAPIMixIn.torrents_file_priority)
def file_priority(
self,
torrent_hash: str | None = None,
file_ids: int | Iterable[str | int] | None = None,
priority: str | int | None = None,
**kwargs: APIKwargsT,
) -> None:
return self._client.torrents_file_priority(
torrent_hash=torrent_hash,
file_ids=file_ids,
priority=priority,
**kwargs,
)

filePrio = file_priority

@wraps(TorrentsAPIMixIn.torrents_rename)
def rename(
self,
torrent_hash: str | None = None,
new_torrent_name: str | None = None,
**kwargs: APIKwargsT,
) -> None:
return self._client.torrents_rename(
torrent_hash=torrent_hash,
new_torrent_name=new_torrent_name,
**kwargs,
)

@wraps(TorrentsAPIMixIn.torrents_rename_file)
def rename_file(
self,
torrent_hash: str | None = None,
file_id: str | int | None = None,
new_file_name: str | None = None,
old_path: str | None = None,
new_path: str | None = None,
**kwargs: APIKwargsT,
) -> None:
return self._client.torrents_rename_file(
torrent_hash=torrent_hash,
file_id=file_id,
new_file_name=new_file_name,
old_path=old_path,
new_path=new_path,
**kwargs,
)

renameFile = rename_file

@wraps(TorrentsAPIMixIn.torrents_rename_folder)
def rename_folder(
self,
torrent_hash: str | None = None,
old_path: str | None = None,
new_path: str | None = None,
**kwargs: APIKwargsT,
) -> None:
return self._client.torrents_rename_folder(
torrent_hash=torrent_hash,
old_path=old_path,
new_path=new_path,
**kwargs,
)

renameFolder = rename_folder

@wraps(TorrentsAPIMixIn.torrents_export)
def export(
self,
torrent_hash: str | None = None,
**kwargs: APIKwargsT,
) -> bytes:
return self._client.torrents_export(torrent_hash=torrent_hash, **kwargs)


class TorrentCategories(ClientCache[TorrentsAPIMixIn]):
"""
Expand Down
12 changes: 12 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
import sys

import pytest

from qbittorrentapi import APINames
from qbittorrentapi._attrdict import AttrDict
from qbittorrentapi.app import NetworkInterface
from qbittorrentapi.app import NetworkInterfaceAddressList
from qbittorrentapi.app import NetworkInterfaceList
from tests.conftest import IS_QBT_DEV


@pytest.mark.skipif(sys.version_info < (3, 9), reason="removeprefix not in 3.8")
def test_methods(client):
namespace = APINames.Application
all_dotted_methods = set(dir(getattr(client, namespace)))

for meth in [meth for meth in dir(client) if meth.startswith(f"{namespace}_")]:
assert meth.removeprefix(f"{namespace}_") in all_dotted_methods


def test_version(client, app_version):
assert client.app_version() == app_version
assert client.app.version == app_version
Expand Down
12 changes: 12 additions & 0 deletions tests/test_auth.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import sys

import pytest

from qbittorrentapi import APINames
from qbittorrentapi import Client
from qbittorrentapi.exceptions import APIConnectionError


@pytest.mark.skipif(sys.version_info < (3, 9), reason="removeprefix not in 3.8")
def test_methods(client):
namespace = APINames.Authorization
all_dotted_methods = set(dir(getattr(client, namespace)))

for meth in [meth for meth in dir(client) if meth.startswith(f"{namespace}_")]:
assert meth.removeprefix(f"{namespace}_") in all_dotted_methods


def test_is_logged_in():
client = Client(
RAISE_NOTIMPLEMENTEDERROR_FOR_UNIMPLEMENTED_API_ENDPOINTS=True,
Expand Down
11 changes: 11 additions & 0 deletions tests/test_log.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import sys

import pytest

from qbittorrentapi.definitions import APINames
from qbittorrentapi.log import LogMainList
from qbittorrentapi.log import LogPeersList


@pytest.mark.skipif(sys.version_info < (3, 9), reason="removeprefix not in 3.8")
def test_methods(client):
namespace = APINames.Log
all_dotted_methods = set(dir(getattr(client, namespace)))

for meth in [meth for meth in dir(client) if meth.startswith(f"{namespace}_")]:
assert meth.removeprefix(f"{namespace}_") in all_dotted_methods


@pytest.mark.parametrize("main_func", ["log_main", "log.main"])
@pytest.mark.parametrize("last_known_id", (None, 0))
def test_log_main_id(client, main_func, last_known_id):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_rss.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys
from time import sleep

import pytest

from qbittorrentapi import APINames
from qbittorrentapi._version_support import v
from qbittorrentapi.exceptions import APIError
from qbittorrentapi.rss import RSSitemsDictionary
Expand Down Expand Up @@ -51,6 +53,15 @@ def delete_feed(name):
yield ""


@pytest.mark.skipif(sys.version_info < (3, 9), reason="removeprefix not in 3.8")
def test_methods(client):
namespace = APINames.RSS
all_dotted_methods = set(dir(getattr(client, namespace)))

for meth in [meth for meth in dir(client) if meth.startswith(f"{namespace}_")]:
assert meth.removeprefix(f"{namespace}_") in all_dotted_methods


@pytest.mark.skipif_before_api_version("2.2.1")
@pytest.mark.parametrize(
"refresh_item_func",
Expand Down
12 changes: 12 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import sys

import pytest

from qbittorrentapi import APINames
from qbittorrentapi import NotFound404Error
from qbittorrentapi.search import SearchCategoriesList
from qbittorrentapi.search import SearchJobDictionary
Expand All @@ -13,6 +16,15 @@
PLUGIN_URL = "https://raw.githubusercontent.com/khensolomon/leyts/master/yts.py"


@pytest.mark.skipif(sys.version_info < (3, 9), reason="removeprefix not in 3.8")
def test_methods(client):
namespace = APINames.Search
all_dotted_methods = set(dir(getattr(client, namespace)))

for meth in [meth for meth in dir(client) if meth.startswith(f"{namespace}_")]:
assert meth.removeprefix(f"{namespace}_") in all_dotted_methods


@pytest.mark.skipif_before_api_version("2.1.1")
@pytest.mark.parametrize(
"update_func", ["search_update_plugins", "search.update_plugins"]
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sync.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import sys

import pytest

from qbittorrentapi import APINames
from qbittorrentapi.sync import SyncMainDataDictionary
from qbittorrentapi.sync import SyncTorrentPeersDictionary


@pytest.mark.skipif(sys.version_info < (3, 9), reason="removeprefix not in 3.8")
def test_methods(client):
namespace = APINames.Sync
all_dotted_methods = set(dir(getattr(client, namespace)))

for meth in [meth for meth in dir(client) if meth.startswith(f"{namespace}_")]:
assert meth.removeprefix(f"{namespace}_") in all_dotted_methods


@pytest.mark.parametrize("maindata_func", ["sync_maindata", "sync.maindata"])
@pytest.mark.parametrize("rid", [None, 0, 1, 100000])
def test_sync_maindata(client, maindata_func, rid):
Expand Down
Loading

0 comments on commit 0a06370

Please sign in to comment.