Better test

This commit is contained in:
Spitap
2023-03-13 14:59:30 +01:00
parent 85652320b6
commit 602405833c
2 changed files with 14 additions and 6 deletions

1
run.py
View File

@@ -203,6 +203,7 @@ def main(input_args):
"Would you like to update it? (Y/n) ") "Would you like to update it? (Y/n) ")
if answer.lower().startswith("y"): if answer.lower().startswith("y"):
config_file_update_complete(utils.update_config(args.configfile)) config_file_update_complete(utils.update_config(args.configfile))
if not args.stop_after_configfile_check:
answer = utils.user_input("Would you like to stop to review the updated config? (Y/n)") answer = utils.user_input("Would you like to stop to review the updated config? (Y/n)")
if answer.lower().startswith("y"): if answer.lower().startswith("y"):
return return

View File

@@ -18,7 +18,6 @@ try:
except ImportError: except ImportError:
from mock import patch from mock import patch
from modoboa_installer import utils
import run import run
@@ -63,7 +62,8 @@ class ConfigFileTestCase(unittest.TestCase):
self.assertEqual(config.get("certificate", "type"), "self-signed") self.assertEqual(config.get("certificate", "type"), "self-signed")
self.assertEqual(config.get("database", "engine"), "postgres") 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.""" """Check configfile update mechanism."""
cfgfile_temp = os.path.join(self.workdir, "installer_old.cfg") cfgfile_temp = os.path.join(self.workdir, "installer_old.cfg")
@@ -82,11 +82,18 @@ class ConfigFileTestCase(unittest.TestCase):
[dummy] [dummy]
weird_old_option = "hey weird_old_option = "hey
""") """)
mock_user_input.side_effect = ["y"]
out = StringIO() out = StringIO()
sys.stdout = out 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.assertIn("dummy", out.getvalue())
self.assertTrue(Path(self.workdir).glob("*.old")) self.assertTrue(Path(self.workdir).glob("*.old"))
self.assertIn("Update complete",
out.getvalue()
)
@patch("modoboa_installer.utils.user_input") @patch("modoboa_installer.utils.user_input")
def test_interactive_mode_letsencrypt(self, mock_user_input): def test_interactive_mode_letsencrypt(self, mock_user_input):