2015-09-04 08:29:20 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import unittest
|
2015-09-20 08:29:12 +02:00
|
|
|
from unittest.mock import patch, call, MagicMock
|
2015-09-04 08:29:20 +02:00
|
|
|
|
2015-09-20 23:14:00 +02:00
|
|
|
from pirate.print import Printer
|
2015-09-04 08:29:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TestPrint(unittest.TestCase):
|
|
|
|
|
|
|
|
def test_print_results(self):
|
2015-09-20 08:29:12 +02:00
|
|
|
class MockTable:
|
|
|
|
add_row = MagicMock()
|
|
|
|
align = {}
|
|
|
|
mock = MockTable()
|
2015-09-20 23:14:00 +02:00
|
|
|
printer = Printer(False)
|
|
|
|
printer.print = MagicMock()
|
2015-09-20 08:29:12 +02:00
|
|
|
with patch('prettytable.PrettyTable', return_value=mock) as prettytable:
|
2015-09-04 08:29:20 +02:00
|
|
|
results = [{
|
|
|
|
'magnet': 'dn=name',
|
|
|
|
'seeds': 1,
|
|
|
|
'leechers': 2,
|
|
|
|
'size': ['3','MiB'],
|
|
|
|
'uploaded': 'never'
|
|
|
|
}]
|
2015-09-20 23:14:00 +02:00
|
|
|
printer.search_results(results)
|
2015-09-20 08:29:12 +02:00
|
|
|
prettytable.assert_called_once_with(['LINK', 'SEED', 'LEECH', 'RATIO', 'SIZE', '', 'UPLOAD', 'NAME'])
|
|
|
|
mock.add_row.assert_has_calls([call([0, 1, 2, '0.5', '3.0', 'MiB', 'never', 'name'])])
|
|
|
|
|
|
|
|
def test_print_results(self):
|
|
|
|
class MockTable:
|
|
|
|
add_row = MagicMock()
|
|
|
|
align = {}
|
|
|
|
mock = MockTable()
|
2015-09-20 23:14:00 +02:00
|
|
|
printer = Printer(False)
|
|
|
|
printer.print = MagicMock()
|
2015-09-20 09:07:23 +02:00
|
|
|
with patch('veryprettytable.VeryPrettyTable', return_value=mock) as prettytable:
|
2015-09-20 08:29:12 +02:00
|
|
|
results = [{
|
|
|
|
'magnet': 'dn=name',
|
|
|
|
'Name': 'name',
|
|
|
|
}]
|
2015-09-20 23:14:00 +02:00
|
|
|
printer.search_results(results, local=True)
|
2015-09-20 08:29:12 +02:00
|
|
|
prettytable.assert_called_once_with(['LINK', 'NAME'])
|
|
|
|
mock.add_row.assert_has_calls([call([0, 'name'])])
|
2015-09-04 08:29:20 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|