-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for Transmission RPC (see #59)
- Loading branch information
Showing
4 changed files
with
180 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import pytest | ||
|
||
from torrt.toolbox import TorrentData | ||
from torrt.utils import Torrent | ||
|
||
|
||
@pytest.fixture | ||
def torrent_data(): | ||
|
||
return TorrentData(parsed=Torrent({ | ||
'info': { | ||
'name': 'mytorr', | ||
'pieces': 1, | ||
'piece length': 1, | ||
'files': [ | ||
{'length': 10, 'path': ['one.avi']}, | ||
{'length': 20, 'path': ['two.avi']}, | ||
{'length': 30, 'path': ['three.avi']}, | ||
{'length': 40, 'path': ['four.avi']}, | ||
], | ||
} | ||
})) | ||
|
||
|
||
@pytest.fixture | ||
def torrent_params(): | ||
return { | ||
'files': { | ||
'mytorr/one.avi': {'name': 'mytorr/one.avi', 'exclude': True, 'priority': 0}, | ||
'mytorr/two.avi': {'name': 'mytorr/two.avi', 'exclude': False, 'priority': 0}, | ||
'mytorr/three.avi': {'name': 'mytorr/three.avi', 'exclude': True, 'priority': 0} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"arguments": { | ||
"torrents": [ | ||
{ | ||
"comment": "somecomment", | ||
"downloadDir": "/home/idle", | ||
"fileStats": [ | ||
{ | ||
"bytesCompleted": 0, | ||
"priority": 0, | ||
"wanted": false | ||
}, | ||
{ | ||
"bytesCompleted": 0, | ||
"priority": 0, | ||
"wanted": true | ||
}, | ||
{ | ||
"bytesCompleted": 0, | ||
"priority": 0, | ||
"wanted": false | ||
} | ||
], | ||
"files": [ | ||
{ | ||
"bytesCompleted": 0, | ||
"length": 10, | ||
"name": "mytorr/one.avi" | ||
}, | ||
{ | ||
"bytesCompleted": 0, | ||
"length": 20, | ||
"name": "mytorr/two.avi" | ||
}, | ||
{ | ||
"bytesCompleted": 0, | ||
"length": 30, | ||
"name": "mytorr/three.avi" | ||
} | ||
], | ||
"hashString": "xxxxx", | ||
"id": 1, | ||
"name": "mytorr" | ||
} | ||
] | ||
}, | ||
"result": "success" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import pytest | ||
|
||
from torrt.rpc.transmission import TransmissionRPC, TransmissionRPCException | ||
|
||
|
||
@pytest.fixture | ||
def transmission(): | ||
rpc = TransmissionRPC() | ||
return rpc | ||
|
||
|
||
def test_auth(response_mock): | ||
|
||
transmission = TransmissionRPC(user='wrong', password='wrongwrong') | ||
|
||
with response_mock( | ||
f'POST {transmission.url} -> 401:<h1>401: Unauthorized</h1>Unauthorized User', | ||
bypass=False | ||
): | ||
with pytest.raises(TransmissionRPCException): | ||
transmission.method_get_version() | ||
|
||
|
||
def test_get_version(response_mock, transmission): | ||
|
||
with response_mock( | ||
f'POST {transmission.url} -> 200:' | ||
'{"arguments":{"rpc-version":15,"rpc-version-minimum":1,"version":"2.94 (d8e60ee44f)"},"result":"success"}\n', | ||
bypass=False | ||
): | ||
version = transmission.method_get_version() | ||
assert version == 15 | ||
|
||
|
||
def test_get_torrents(response_mock, transmission, datafix_read, torrent_params): | ||
|
||
with response_mock( | ||
f"POST {transmission.url} -> 200:{datafix_read('transm_gettorents.json')}", | ||
bypass=False | ||
): | ||
response = transmission.method_get_torrents(hashes=['xxxxx']) | ||
assert response == [{ | ||
'comment': 'somecomment', | ||
'downloadDir': '/home/idle', | ||
'hashString': 'xxxxx', | ||
'id': 1, | ||
'name': 'mytorr', | ||
'hash': 'xxxxx', | ||
'download_to': '/home/idle', | ||
'params': torrent_params, | ||
}] | ||
|
||
|
||
def test_remove_torrent(response_mock, transmission): | ||
|
||
with response_mock( | ||
f'POST {transmission.url} -> 200:' | ||
'{"arguments":{},"result":"success"}', | ||
bypass=False | ||
): | ||
response = transmission.method_remove_torrent(hash_str='xxxxx') | ||
assert response == {} | ||
|
||
|
||
def test_add_torrent(response_mock, transmission, torrent_params, torrent_data): | ||
|
||
with response_mock( | ||
f'POST {transmission.url} -> 200:' | ||
'{"arguments":{},"result":"success"}', | ||
bypass=False | ||
): | ||
response = transmission.method_add_torrent( | ||
torrent=torrent_data, | ||
download_to='/here/', | ||
params=torrent_params, | ||
) | ||
assert response == {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters