mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
test_remote
This commit is contained in:
parent
8a371dea56
commit
f43e08c18c
@ -109,15 +109,30 @@ class TestTorrent(unittest.TestCase):
|
|||||||
pirate.torrent.save_magnets([0], [{'magnet':magnet}], 'path')
|
pirate.torrent.save_magnets([0], [{'magnet':magnet}], 'path')
|
||||||
open_.assert_called_once_with('path/Test Drive Unlimited [PC Version].magnet', 'w')
|
open_.assert_called_once_with('path/Test Drive Unlimited [PC Version].magnet', 'w')
|
||||||
|
|
||||||
def test_get_torrent(self):
|
@patch('urllib.request.urlopen')
|
||||||
with patch('urllib.request.urlopen') as urlopen:
|
def test_get_torrent(self, urlopen):
|
||||||
class MockResponse():
|
class MockRequest():
|
||||||
add_header = mock.MagicMock()
|
add_header = mock.MagicMock()
|
||||||
response = MockResponse()
|
request_obj = MockRequest()
|
||||||
with patch('urllib.request.Request', return_value=response) as request:
|
with patch('urllib.request.Request', return_value=request_obj) as request:
|
||||||
pirate.torrent.get_torrent(100000000000000)
|
pirate.torrent.get_torrent(100000000000000)
|
||||||
request.assert_called_once_with('http://torcache.net/torrent/5AF3107A4000.torrent', headers=pirate.data.default_headers)
|
request.assert_called_once_with('http://torcache.net/torrent/5AF3107A4000.torrent', headers=pirate.data.default_headers)
|
||||||
urlopen.assert_called_once_with(response, timeout=pirate.data.default_timeout)
|
urlopen.assert_called_once_with(request_obj, timeout=pirate.data.default_timeout)
|
||||||
|
|
||||||
|
def test_remote(self):
|
||||||
|
class MockRequest():
|
||||||
|
add_header = mock.MagicMock()
|
||||||
|
request_obj = MockRequest()
|
||||||
|
class MockResponse():
|
||||||
|
read = mock.MagicMock(return_value='<html>No hits. Try adding an asterisk in you search phrase.</html>'.encode('utf8'))
|
||||||
|
info = mock.MagicMock()
|
||||||
|
response_obj = MockResponse()
|
||||||
|
with patch('urllib.request.Request', return_value=request_obj) as request:
|
||||||
|
with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
|
||||||
|
res = pirate.torrent.remote(1, 100, 10, 'browse', [], 'http://example.com')
|
||||||
|
request.assert_called_once_with('http://example.com/browse/100/0/10', headers=pirate.data.default_headers)
|
||||||
|
urlopen.assert_called_once_with(request_obj, timeout=pirate.data.default_timeout)
|
||||||
|
self.assertEqual(res, [])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user