diff options
author | Konstantin Khukalenko <4685683+hukal@users.noreply.github.com> | 2018-12-09 22:14:31 +0300 |
---|---|---|
committer | Calum Lind <calumlind+deluge@gmail.com> | 2019-05-11 22:33:18 +0100 |
commit | f885edd7fc85fccb39f4e28f5c279cc4299c1762 (patch) | |
tree | e5637ad6698c532036a5b646f586a1bcd4f973a6 | |
parent | 2b171e58a32bed9952da4169a2d47d09182d4470 (diff) | |
download | deluge-f885edd7fc85fccb39f4e28f5c279cc4299c1762.tar.gz deluge-f885edd7fc85fccb39f4e28f5c279cc4299c1762.tar.bz2 deluge-f885edd7fc85fccb39f4e28f5c279cc4299c1762.zip |
[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>
-rw-r--r-- | deluge/tests/__init__.py | 5 | ||||
-rw-r--r-- | deluge/tests/common.py | 5 | ||||
-rw-r--r-- | deluge/tests/test_ui_console.py (renamed from deluge/tests/test_ui_console_fields.py) | 29 | ||||
-rw-r--r-- | deluge/tests/test_ui_entry.py | 49 | ||||
-rw-r--r-- | deluge/ui/console/cmdline/commands/add.py | 14 |
5 files changed, 89 insertions, 13 deletions
diff --git a/deluge/tests/__init__.py b/deluge/tests/__init__.py index cc18352b9..d3bf10def 100644 --- a/deluge/tests/__init__.py +++ b/deluge/tests/__init__.py @@ -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() diff --git a/deluge/tests/common.py b/deluge/tests/common.py index 0fb8d5002..e92cc0f91 100644 --- a/deluge/tests/common.py +++ b/deluge/tests/common.py @@ -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 diff --git a/deluge/tests/test_ui_console_fields.py b/deluge/tests/test_ui_console.py index a844184a1..8c67322ee 100644 --- a/deluge/tests/test_ui_console_fields.py +++ b/deluge/tests/test_ui_console.py @@ -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) diff --git a/deluge/tests/test_ui_entry.py b/deluge/tests/test_ui_entry.py index 46ec2a421..1d405a153 100644 --- a/deluge/tests/test_ui_entry.py +++ b/deluge/tests/test_ui_entry.py @@ -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,7 +391,35 @@ 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) @@ -399,6 +428,20 @@ class ConsoleUIWithDaemonBaseTestCase(UIWithDaemonBaseTestCase): 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: ') and std_output.endswith(' Moving: 0\n') ) diff --git a/deluge/ui/console/cmdline/commands/add.py b/deluge/ui/console/cmdline/commands/add.py index e2baf2740..34881d887 100644 --- a/deluge/ui/console/cmdline/commands/add.py +++ b/deluge/ui/console/cmdline/commands/add.py @@ -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') |