Added unit test.
This commit is contained in:
@@ -6,7 +6,7 @@ python:
|
||||
- "3.4"
|
||||
|
||||
before_install:
|
||||
- pip install codecov
|
||||
- pip install -r test-requirements.txt
|
||||
|
||||
script:
|
||||
- coverage run tests.py
|
||||
|
||||
@@ -249,16 +249,17 @@ def get_entry_value(entry, interactive):
|
||||
user_value = None
|
||||
if entry.get("customizable") and interactive:
|
||||
while (user_value != '' and not validate(user_value, entry)):
|
||||
print(entry.get("question"))
|
||||
question = entry.get("question")
|
||||
if entry.get("values"):
|
||||
print("Please choose from the list")
|
||||
question += " from the list"
|
||||
values = entry.get("values")
|
||||
for index, value in enumerate(values):
|
||||
print("{} {}".format(index, value))
|
||||
question += "\n{} {}".format(index, value)
|
||||
print(question)
|
||||
print("default is <{}>".format(default_value))
|
||||
user_value = user_input("-> ")
|
||||
|
||||
if entry.get("values") and user_value != '':
|
||||
if entry.get("values") and user_value != "":
|
||||
user_value = values[int(user_value)]
|
||||
return user_value if user_value else default_value
|
||||
|
||||
|
||||
2
test-requirements.txt
Normal file
2
test-requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
codecov
|
||||
mock
|
||||
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