1
0
mirror of https://github.com/vikstrous/pirate-get synced 2025-01-10 10:04:21 +01:00

Merge pull request #70 from vikstrous/more_tests4

test basic choice of torrent
This commit is contained in:
Viktor Stanchev 2015-09-20 17:24:12 -07:00
commit f0f17b8b8f
2 changed files with 32 additions and 15 deletions

View File

@ -7,6 +7,7 @@ import socket
import urllib.request as request import urllib.request as request
import urllib.error import urllib.error
import sys import sys
import builtins
from collections import OrderedDict from collections import OrderedDict
import webbrowser import webbrowser
@ -325,7 +326,7 @@ def pirate_main(args):
printer.print("\nSelect links (Type 'h' for more options" printer.print("\nSelect links (Type 'h' for more options"
", 'q' to quit)", end='\b', color='alt') ", 'q' to quit)", end='\b', color='alt')
try: try:
l = input(': ') l = builtins.input(': ')
except (KeyboardInterrupt, EOFError): except (KeyboardInterrupt, EOFError):
printer.print('\nCancelled.') printer.print('\nCancelled.')
return return

View File

@ -23,20 +23,36 @@ class TestPirate(unittest.TestCase):
for test in tests: for test in tests:
self.assertEqual(pirate.pirate.parse_cmd(*test[0]), test[1]) self.assertEqual(pirate.pirate.parse_cmd(*test[0]), test[1])
def test_main(self): @patch('subprocess.call')
with patch('subprocess.call') as mock_call: def test_main(self, mock_call):
result = { result = {
'magnet': 'dn=derp', 'magnet': 'dn=derp',
'seeds': '1', 'seeds': '1',
'leechers': '1', 'leechers': '1',
'size': ('1', 'mb'), 'size': ('1', 'mb'),
'uploaded': '1', 'uploaded': '1',
} }
with patch('pirate.torrent.remote', return_value=[result]) as mock_remote: with patch('pirate.torrent.remote', return_value=[result]) as mock_remote:
config = pirate.pirate.parse_config_file('') config = pirate.pirate.parse_config_file('')
args = pirate.pirate.combine_configs(config, pirate.pirate.parse_args(['-0', 'term', '-C', 'blah %s'])) args = pirate.pirate.combine_configs(config, pirate.pirate.parse_args(['-0', 'term', '-C', 'blah %s']))
pirate.pirate.pirate_main(args) pirate.pirate.pirate_main(args)
mock_call.assert_called_once_with(['blah', 'dn=derp']) mock_call.assert_called_once_with(['blah', 'dn=derp'])
@patch('pirate.pirate.builtins.input', return_value='0')
@patch('subprocess.call')
def test_main_choice(self, mock_call, mock_input):
result = {
'magnet': 'dn=derp',
'seeds': '1',
'leechers': '1',
'size': ('1', 'mb'),
'uploaded': '1',
}
with patch('pirate.torrent.remote', return_value=[result]) as mock_remote:
config = pirate.pirate.parse_config_file('')
args = pirate.pirate.combine_configs(config, pirate.pirate.parse_args(['term', '-C', 'blah %s']))
pirate.pirate.pirate_main(args)
mock_call.assert_called_once_with(['blah', 'dn=derp'])
def test_parse_torrent_command(self): def test_parse_torrent_command(self):
tests = [ tests = [