63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
"""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
|
|
|
|
|
|
class ConfigFileTestCase(unittest.TestCase):
|
|
"""Test configuration file generation."""
|
|
|
|
def setUp(self):
|
|
"""Create temp dir."""
|
|
self.workdir = tempfile.mkdtemp()
|
|
self.cfgfile = os.path.join(self.workdir, "installer.cfg")
|
|
|
|
def tearDown(self):
|
|
"""Delete temp dir."""
|
|
shutil.rmtree(self.workdir)
|
|
|
|
def test_configfile_generation(self):
|
|
"""Check simple case."""
|
|
run.main([
|
|
"--stop-after-configfile-check",
|
|
"--configfile", self.cfgfile,
|
|
"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()
|