From 602405833cde33c43e1d6353c378a689ed967334 Mon Sep 17 00:00:00 2001 From: Spitap Date: Mon, 13 Mar 2023 14:59:30 +0100 Subject: [PATCH] Better test --- run.py | 7 ++++--- tests.py | 13 ++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/run.py b/run.py index b23be66..269c1d3 100755 --- a/run.py +++ b/run.py @@ -203,9 +203,10 @@ def main(input_args): "Would you like to update it? (Y/n) ") if answer.lower().startswith("y"): config_file_update_complete(utils.update_config(args.configfile)) - answer = utils.user_input("Would you like to stop to review the updated config? (Y/n)") - if answer.lower().startswith("y"): - return + if not args.stop_after_configfile_check: + answer = utils.user_input("Would you like to stop to review the updated config? (Y/n)") + if answer.lower().startswith("y"): + return else: utils.error("You might encounter unexpected errors ! " "Make sur to update your config before opening an issue!") diff --git a/tests.py b/tests.py index d3e2579..6f8fdf6 100644 --- a/tests.py +++ b/tests.py @@ -18,7 +18,6 @@ try: except ImportError: from mock import patch -from modoboa_installer import utils import run @@ -63,7 +62,8 @@ class ConfigFileTestCase(unittest.TestCase): self.assertEqual(config.get("certificate", "type"), "self-signed") self.assertEqual(config.get("database", "engine"), "postgres") - def test_updating_configfile(self): + @patch("modoboa_installer.utils.user_input") + def test_updating_configfile(self, mock_user_input): """Check configfile update mechanism.""" cfgfile_temp = os.path.join(self.workdir, "installer_old.cfg") @@ -82,11 +82,18 @@ class ConfigFileTestCase(unittest.TestCase): [dummy] weird_old_option = "hey """) + mock_user_input.side_effect = ["y"] out = StringIO() sys.stdout = out - utils.update_config(cfgfile_temp) + run.main([ + "--stop-after-configfile-check", + "--configfile", cfgfile_temp, + "example.test"]) self.assertIn("dummy", out.getvalue()) self.assertTrue(Path(self.workdir).glob("*.old")) + self.assertIn("Update complete", + out.getvalue() + ) @patch("modoboa_installer.utils.user_input") def test_interactive_mode_letsencrypt(self, mock_user_input):