From c0259eb435a63ba686d7b145adcb9ef9dbd7d2ee Mon Sep 17 00:00:00 2001 From: Viktor Stanchev Date: Sun, 20 Sep 2015 14:40:41 -0700 Subject: [PATCH] test printing file lists and descriptions --- tests/test_print.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/tests/test_print.py b/tests/test_print.py index 9022f7d..52c0bfb 100755 --- a/tests/test_print.py +++ b/tests/test_print.py @@ -42,5 +42,35 @@ class TestPrint(unittest.TestCase): prettytable.assert_called_once_with(['LINK', '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='
stuff link
'.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='1.filename'.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__': unittest.main()