mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-09 09:59:51 +01:00
fix tests with custom url opener
This commit is contained in:
parent
95782b0974
commit
c6f742893c
@ -93,8 +93,12 @@ class TestPrint(unittest.TestCase):
|
||||
read = MagicMock(return_value='<html><div class="nfo"><pre>stuff <a href="href">link</a></pre></div></html>'.encode('utf8'))
|
||||
info = MagicMock()
|
||||
response_obj = MockResponse()
|
||||
class MockOpener():
|
||||
open = MagicMock(return_value=response_obj)
|
||||
add_handler = MagicMock()
|
||||
opener_obj = MockOpener()
|
||||
with patch('urllib.request.Request', return_value=request_obj) as request:
|
||||
with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
|
||||
with patch('urllib.request.OpenerDirector', return_value=opener_obj) as opener:
|
||||
printer.descriptions([0], [{'id': '1', 'magnet': 'dn=name'}], 'example.com')
|
||||
printer.print.assert_has_calls([call('Description for "name":', color='zebra_1'),call('stuff [link](href)', color='zebra_0')])
|
||||
|
||||
@ -108,8 +112,12 @@ class TestPrint(unittest.TestCase):
|
||||
read = MagicMock(return_value='<html><tr><td align="left">1.</td><td align="right">filename</tr></html>'.encode('utf8'))
|
||||
info = MagicMock()
|
||||
response_obj = MockResponse()
|
||||
class MockOpener():
|
||||
open = MagicMock(return_value=response_obj)
|
||||
add_handler = MagicMock()
|
||||
opener_obj = MockOpener()
|
||||
with patch('urllib.request.Request', return_value=request_obj) as request:
|
||||
with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
|
||||
with patch('urllib.request.OpenerDirector', return_value=opener_obj) as opener:
|
||||
printer.file_lists([0], [{'id': '1', 'magnet': 'dn=name'}], 'example.com')
|
||||
printer.print.assert_has_calls([call('Files in "name":', color='zebra_1'),call(' 1. filename', color='zebra_0')])
|
||||
|
||||
|
@ -124,14 +124,18 @@ class TestTorrent(unittest.TestCase):
|
||||
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'))
|
||||
read = mock.MagicMock(return_value=b'<html>No hits. Try adding an asterisk in you search phrase.</html>')
|
||||
info = mock.MagicMock()
|
||||
response_obj = MockResponse()
|
||||
class MockOpener():
|
||||
open = mock.MagicMock(return_value=response_obj)
|
||||
add_handler = mock.MagicMock()
|
||||
opener_obj = MockOpener()
|
||||
with patch('urllib.request.Request', return_value=request_obj) as request:
|
||||
with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
|
||||
with patch('urllib.request.OpenerDirector', return_value=opener_obj) as opener:
|
||||
res = pirate.torrent.remote(MagicMock(Printer), 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)
|
||||
opener_obj.open.assert_called_once_with(request_obj, timeout=pirate.data.default_timeout)
|
||||
self.assertEqual(res, [])
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
Reference in New Issue
Block a user