Skip to content

Commit

Permalink
Fixed qbittorrent torren removal (fix #72)
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Oct 21, 2021
1 parent c29d1ac commit 73c43d1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Expand Up @@ -2,6 +2,11 @@ torrt changelog
===============


Unreleased
----------
* Fixed qbittorrent torren removal (fix #72).


v0.16.3 [2021-10-13]
--------------------
* Fixed qbittorrent 'savepath' is not a valid torrent file (fix #71).
Expand Down
29 changes: 28 additions & 1 deletion tests/rpc/test_qbittorrent.py
Expand Up @@ -5,7 +5,7 @@

@pytest.fixture
def qbit():
rpc = QBittorrentRPC()
rpc = QBittorrentRPC(password='adminadmin')
return rpc


Expand Down Expand Up @@ -41,3 +41,30 @@ def test_add_torrent(response_mock, qbit, torrent_params, torrent_data):
params=torrent_params,
)
assert response.ok


def test_remove_torrent(response_mock, qbit, torrent_params, torrent_data):

with response_mock([
f'POST {qbit.url}auth/login -> 200:Ok.',
f'POST {qbit.url}torrents/delete -> 200:',
],
bypass=False
):
response = qbit.method_remove_torrent(
hash_str='3dc61b1936e55d983ad774bf59b932b0a31eedd3',
with_data=True,
)
assert response.ok


def test_get_version(response_mock, qbit, torrent_params, torrent_data):

with response_mock([
f'POST {qbit.url}auth/login -> 200:Ok.',
f'GET {qbit.url}app/webapiVersion -> 200:2.2',
],
bypass=False
):
response = qbit.method_get_version()
assert response == '2.2'
14 changes: 7 additions & 7 deletions torrt/rpc/qbittorrent.py
Expand Up @@ -88,7 +88,7 @@ def get_request_url(self, params: dict) -> str:
if 'action_params' in params:
url_segment = url_segment % params['action_params']

return urljoin(self.url, url_segment )
return urljoin(self.url, url_segment)

def query(self, data: dict, files: dict = None) -> Response:

Expand Down Expand Up @@ -178,18 +178,18 @@ def method_add_torrent(self, torrent: TorrentData, download_to: str = None, para
params = None

if download_to is not None:
params = {'data':{'savepath': download_to}}
params = {'data': {'savepath': download_to}}

return self.auth_query(self.build_params(action='add_torrent', params=params), file_data)

def method_remove_torrent(self, hash_str: str, with_data: bool = False) -> Any:

data = {'hashes': hash_str}
data = {
'hashes': hash_str,
'deleteFiles': 'true' if with_data else 'false',
}

if with_data:
data['deleteFiles'] = 'true'

return self.auth_query(self.build_params('rem_torrent', {'data': data}))
return self.auth_query(self.build_params(action='rem_torrent', params={'data': data}))

def method_get_version(self) -> str:
result = self.auth_query(self.build_params(action='api_version_path'))
Expand Down

0 comments on commit 73c43d1

Please sign in to comment.