[Console] Add move completed option to add torrent command
- Added a -m|--move-completed option for specifying a move completed path when adding a torrent. - Re-used existing console test and renamed for generic usage. - Moved setup_translation to tests.__init__ so it is always setup instead of relying on tests.common import. Closes #2847 Co-authored-by: Calum Lind <calumlind+deluge@gmail.com>
This commit is contained in:
parent
2b171e58a3
commit
f885edd7fc
|
@ -2,6 +2,8 @@
|
|||
# without getting error: what(): epoll: Too many open files
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
from deluge.i18n import setup_translation
|
||||
|
||||
try:
|
||||
import resource
|
||||
except ImportError: # Does not exist on Windows
|
||||
|
@ -12,3 +14,6 @@ else:
|
|||
except (ValueError, resource.error) as ex:
|
||||
error = 'Failed to raise file descriptor limit: %s' % ex
|
||||
# print(error)
|
||||
|
||||
# Initialize gettext
|
||||
setup_translation()
|
||||
|
|
|
@ -23,7 +23,6 @@ import deluge.configmanager
|
|||
import deluge.core.preferencesmanager
|
||||
import deluge.log
|
||||
from deluge.error import DelugeError
|
||||
from deluge.i18n import setup_translation
|
||||
|
||||
# This sets log level to critical, so use log.critical() to debug while running unit tests
|
||||
deluge.log.setup_logger('none')
|
||||
|
@ -74,10 +73,6 @@ def add_watchdog(deferred, timeout=0.05, message=None):
|
|||
return watchdog
|
||||
|
||||
|
||||
# Initialize gettext
|
||||
setup_translation()
|
||||
|
||||
|
||||
class ReactorOverride(object):
|
||||
"""Class used to patch reactor while running unit tests
|
||||
to avoid starting and stopping the twisted reactor
|
||||
|
|
|
@ -7,22 +7,25 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from twisted.trial import unittest
|
||||
import argparse
|
||||
|
||||
from deluge.common import windows_check
|
||||
from deluge.ui.console.cmdline.commands.add import Command
|
||||
from deluge.ui.console.widgets.fields import TextInput
|
||||
|
||||
from .basetest import BaseTestCase
|
||||
|
||||
class Parent(object):
|
||||
|
||||
class MockParent(object):
|
||||
def __init__(self):
|
||||
self.border_off_x = 1
|
||||
self.pane_width = 20
|
||||
self.encoding = 'utf8'
|
||||
|
||||
|
||||
class UICommonTestCase(unittest.TestCase):
|
||||
class UIConsoleFieldTestCase(BaseTestCase):
|
||||
def setUp(self): # NOQA: N803
|
||||
self.parent = Parent()
|
||||
self.parent = MockParent()
|
||||
|
||||
def tearDown(self): # NOQA: N803
|
||||
pass
|
||||
|
@ -44,3 +47,21 @@ class UICommonTestCase(unittest.TestCase):
|
|||
self.assertTrue(t)
|
||||
if not windows_check():
|
||||
self.assertTrue(t.handle_read(33))
|
||||
|
||||
|
||||
class UIConsoleCommandsTestCase(BaseTestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_add_move_completed(self):
|
||||
completed_path = 'completed_path'
|
||||
parser = argparse.ArgumentParser()
|
||||
cmd = Command()
|
||||
cmd.add_arguments(parser)
|
||||
args = parser.parse_args(['torrent', '-m', completed_path])
|
||||
self.assertEqual(args.move_completed_path, completed_path)
|
||||
args = parser.parse_args(['torrent', '--move-path', completed_path])
|
||||
self.assertEqual(args.move_completed_path, completed_path)
|
|
@ -377,8 +377,9 @@ class ConsoleUIWithDaemonBaseTestCase(UIWithDaemonBaseTestCase):
|
|||
deluge.ui.console.main.reactor = common.ReactorOverride()
|
||||
return UIWithDaemonBaseTestCase.set_up(self)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_console_command_status(self):
|
||||
def patch_arg_command(self, command):
|
||||
if type(command) == str:
|
||||
command = [command]
|
||||
username, password = get_localhost_auth()
|
||||
self.patch(
|
||||
sys,
|
||||
|
@ -390,13 +391,55 @@ class ConsoleUIWithDaemonBaseTestCase(UIWithDaemonBaseTestCase):
|
|||
+ [username]
|
||||
+ ['--password']
|
||||
+ [password]
|
||||
+ ['status'],
|
||||
+ command,
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_console_command_add(self):
|
||||
filename = common.get_test_data_file('test.torrent')
|
||||
self.patch_arg_command(['add ' + filename])
|
||||
fd = StringFileDescriptor(sys.stdout)
|
||||
self.patch(sys, 'stdout', fd)
|
||||
|
||||
yield self.exec_command()
|
||||
|
||||
std_output = fd.out.getvalue()
|
||||
self.assertTrue(
|
||||
std_output
|
||||
== 'Attempting to add torrent: ' + filename + '\nTorrent added!\n'
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_console_command_add_move_completed(self):
|
||||
filename = common.get_test_data_file('test.torrent')
|
||||
self.patch_arg_command(
|
||||
[
|
||||
'add --move-path /tmp ' + filename + ' ; status'
|
||||
' ; manage'
|
||||
' ab570cdd5a17ea1b61e970bb72047de141bce173'
|
||||
' move_completed'
|
||||
' move_completed_path'
|
||||
]
|
||||
)
|
||||
fd = StringFileDescriptor(sys.stdout)
|
||||
self.patch(sys, 'stdout', fd)
|
||||
|
||||
yield self.exec_command()
|
||||
|
||||
std_output = fd.out.getvalue()
|
||||
self.assertTrue(
|
||||
std_output.endswith('move_completed: True\nmove_completed_path: /tmp\n')
|
||||
or std_output.endswith('move_completed_path: /tmp\nmove_completed: True\n')
|
||||
)
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def test_console_command_status(self):
|
||||
fd = StringFileDescriptor(sys.stdout)
|
||||
self.patch_arg_command(['status'])
|
||||
self.patch(sys, 'stdout', fd)
|
||||
|
||||
yield self.exec_command()
|
||||
|
||||
std_output = fd.out.getvalue()
|
||||
self.assertTrue(
|
||||
std_output.startswith('Total upload: ')
|
||||
|
|
|
@ -35,7 +35,13 @@ class Command(BaseCommand):
|
|||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument(
|
||||
'-p', '--path', dest='path', help=_('download folder for torrent')
|
||||
'-p', '--path', dest='path', help=_('Download folder for torrent')
|
||||
)
|
||||
parser.add_argument(
|
||||
'-m',
|
||||
'--move-path',
|
||||
dest='move_completed_path',
|
||||
help=_('Move the completed torrent to this folder'),
|
||||
)
|
||||
parser.add_argument(
|
||||
'torrents',
|
||||
|
@ -53,6 +59,12 @@ class Command(BaseCommand):
|
|||
os.path.expanduser(options.path)
|
||||
)
|
||||
|
||||
if options.move_completed_path:
|
||||
t_options['move_completed'] = True
|
||||
t_options['move_completed_path'] = os.path.abspath(
|
||||
os.path.expanduser(options.move_completed_path)
|
||||
)
|
||||
|
||||
def on_success(result):
|
||||
if not result:
|
||||
self.console.write('{!error!}Torrent was not added: Already in session')
|
||||
|
|
Loading…
Reference in New Issue