From e9f0e60608d3780ff4ae1687ebd64c8340df5900 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sun, 29 Dec 2019 11:21:18 -0600 Subject: [PATCH] added toggle bootstrap command --- src/onionrcommands/parser/arguments.py | 9 ++++-- src/onionrcommands/togglebootstrap.py | 32 +++++++++++++++++++ ...est_commands.py => test_commands_basic.py} | 0 tests/test_toggle_bootstrap.py | 20 ++++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 src/onionrcommands/togglebootstrap.py rename tests/{test_commands.py => test_commands_basic.py} (100%) create mode 100644 tests/test_toggle_bootstrap.py diff --git a/src/onionrcommands/parser/arguments.py b/src/onionrcommands/parser/arguments.py index 45180f1d..6fca7921 100644 --- a/src/onionrcommands/parser/arguments.py +++ b/src/onionrcommands/parser/arguments.py @@ -14,9 +14,10 @@ from .. import resettor # cmds to reset the tor data folder/transport keypair from .. import resetplugins # command to reinstall default plugins from .. import softreset # command to delete onionr blocks from .. import restartonionr # command to restart Onionr -from .. import runtimetestcmd -from .. import motdcreator -from .. import sitecreator +from .. import runtimetestcmd # cmd to execute the runtime integration tests +from .. import motdcreator # cmd to generate new Onionr MOTDs +from .. import sitecreator # cmd to create multi-page sites +from .. import togglebootstrap # cmd to toggle bootstrap file usage import onionrexceptions from onionrutils import importnewblocks # func to import new blocks @@ -70,6 +71,8 @@ def get_arguments() -> dict: ('resetplugins', 'reset-plugins'): resetplugins.reset, ('reset-tor-node-transport',): resettor.reset_tor_key_pair, ('soft-reset', 'softreset'): softreset.soft_reset, + ('toggle-bootstrap', 'togglebootstrap'): + togglebootstrap.toggle_bootstrap_config, ('runtime-test', 'runtimetest'): runtimetestcmd.do_runtime_test, ('makemotd', 'make-motd'): motdcreator.motd_creator diff --git a/src/onionrcommands/togglebootstrap.py b/src/onionrcommands/togglebootstrap.py new file mode 100644 index 00000000..0e25bf43 --- /dev/null +++ b/src/onionrcommands/togglebootstrap.py @@ -0,0 +1,32 @@ +"""Onionr - Private P2P Communication. + +Toggle the bootstrap configuration +""" +import sys + +import config +import logger +""" + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +""" + + +def toggle_bootstrap_config(): + """Toggles the bootstrap configuration.""" + print("test") + if config.get('general.use_bootstrap_list') is None: + logger.error('No general.bootstrap_list setting found') + sys.exit(3) + flipped: bool = not config.get('general.use_bootstrap_list') + config.set('general.use_bootstrap_list', flipped, savefile=True) diff --git a/tests/test_commands.py b/tests/test_commands_basic.py similarity index 100% rename from tests/test_commands.py rename to tests/test_commands_basic.py diff --git a/tests/test_toggle_bootstrap.py b/tests/test_toggle_bootstrap.py new file mode 100644 index 00000000..d8b00bbe --- /dev/null +++ b/tests/test_toggle_bootstrap.py @@ -0,0 +1,20 @@ +from unittest.mock import patch +import sys, os +sys.path.append(".") +sys.path.append("src/") +import unittest, uuid +import config +TEST_DIR = 'testdata/%s-%s' % (uuid.uuid4(), os.path.basename(__file__)) + '/' +print("Test directory:", TEST_DIR) +os.environ["ONIONR_HOME"] = TEST_DIR +from onionrcommands import parser +class TestToggleBootstrap(unittest.TestCase): + def test_toggle_bootstrap(self): + testargs = ["onionr.py", "togglebootstrap"] + self.assertTrue(config.get('general.use_bootstrap_list')) + with patch.object(sys, 'argv', testargs): + parser.register() + config.reload() + self.assertFalse(config.get('general.use_bootstrap_list')) + +unittest.main()