mirror of
https://github.com/vikstrous/pirate-get
synced 2025-01-10 10:04:21 +01:00
test printing file lists and descriptions
This commit is contained in:
parent
b9437052da
commit
c0259eb435
@ -42,5 +42,35 @@ class TestPrint(unittest.TestCase):
|
|||||||
prettytable.assert_called_once_with(['LINK', 'NAME'])
|
prettytable.assert_called_once_with(['LINK', 'NAME'])
|
||||||
mock.add_row.assert_has_calls([call([0, 'name'])])
|
mock.add_row.assert_has_calls([call([0, 'name'])])
|
||||||
|
|
||||||
|
def test_print_descriptions(self):
|
||||||
|
printer = Printer(False)
|
||||||
|
printer.print = MagicMock()
|
||||||
|
class MockRequest():
|
||||||
|
add_header = MagicMock()
|
||||||
|
request_obj = MockRequest()
|
||||||
|
class MockResponse():
|
||||||
|
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()
|
||||||
|
with patch('urllib.request.Request', return_value=request_obj) as request:
|
||||||
|
with patch('urllib.request.urlopen', return_value=response_obj) as urlopen:
|
||||||
|
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')])
|
||||||
|
|
||||||
|
def test_print_file_lists(self):
|
||||||
|
printer = Printer(False)
|
||||||
|
printer.print = MagicMock()
|
||||||
|
class MockRequest():
|
||||||
|
add_header = MagicMock()
|
||||||
|
request_obj = MockRequest()
|
||||||
|
class MockResponse():
|
||||||
|
read = MagicMock(return_value='<html><tr><td align="left">1.</td><td align="right">filename</tr></html>'.encode('utf8'))
|
||||||
|
info = 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:
|
||||||
|
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')])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user