Added unit test.

This commit is contained in:
Antoine Nguyen
2017-10-08 15:26:59 +02:00
parent fe54e990b5
commit 7c0346d281
4 changed files with 38 additions and 6 deletions

View File

@@ -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()