Added unit test.
This commit is contained in:
29
tests.py
29
tests.py
@@ -1,10 +1,20 @@
|
||||
"""Installer unit tests."""
|
||||
|
||||
try:
|
||||
import configparser
|
||||
except ImportError:
|
||||
import ConfigParser as configparser
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
try:
|
||||
from unittest.mock import patch
|
||||
except ImportError:
|
||||
from mock import patch
|
||||
|
||||
import run
|
||||
|
||||
|
||||
@@ -28,6 +38,25 @@ class ConfigFileTestCase(unittest.TestCase):
|
||||
"example.test"])
|
||||
self.assertTrue(os.path.exists(self.cfgfile))
|
||||
|
||||
@patch("modoboa_installer.utils.user_input")
|
||||
def test_interactive_mode(self, mock_user_input):
|
||||
"""Check interactive mode."""
|
||||
mock_user_input.side_effect = [
|
||||
"0", "0", "", "", "", ""
|
||||
]
|
||||
with open(os.devnull, "w") as fp:
|
||||
sys.stdout = fp
|
||||
run.main([
|
||||
"--stop-after-configfile-check",
|
||||
"--configfile", self.cfgfile,
|
||||
"--interactive",
|
||||
"example.test"])
|
||||
self.assertTrue(os.path.exists(self.cfgfile))
|
||||
config = configparser.ConfigParser()
|
||||
config.read(self.cfgfile)
|
||||
self.assertEqual(config.get("certificate", "type"), "self-signed")
|
||||
self.assertEqual(config.get("database", "engine"), "postgres")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user