Added a simple unit test for setup_param_factory.py

This commit is contained in:
VakarisZ 2021-05-20 13:51:52 +03:00
parent 9f469a8ec0
commit df5cec6323
3 changed files with 16 additions and 28 deletions

View File

@ -1,6 +1,5 @@
import os
from monkey_island import config_file_parser
from monkey_island.cc.arg_parser import IslandArgs
from monkey_island.setup.setup_params import SetupParams

View File

@ -0,0 +1,16 @@
from monkey_island import config_file_parser
from monkey_island.cc.arg_parser import IslandArgs
from monkey_island.setup.setup_param_factory import SetupParamFactory
MOCK_ISLAND_CMD_ARGS = IslandArgs(setup_only=True, server_config_path="/temp/test_path")
def test_setup_param_factory_build(monkeypatch, test_server_config):
config_contents = config_file_parser.load_server_config_from_file(test_server_config)
setup_params = SetupParamFactory().build(MOCK_ISLAND_CMD_ARGS, config_contents)
assert setup_params.setup_only
assert setup_params.server_config_path == MOCK_ISLAND_CMD_ARGS.server_config_path
assert setup_params.start_mongodb
assert setup_params.log_level == "NOTICE"
assert setup_params.data_dir == "~/.monkey_island"

View File

@ -1,27 +0,0 @@
import os
from monkey_island import config_loader
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR
def test_load_server_config_from_file(test_server_config, mock_home_env):
config = config_loader.load_server_config_from_file(test_server_config)
assert config["data_dir"] == os.path.join(mock_home_env, ".monkey_island")
assert config["log_level"] == "NOTICE"
def test_default_log_level():
test_config = {}
config = config_loader.add_default_values_to_config(test_config)
assert "log_level" in config
assert config["log_level"] == "INFO"
def test_default_data_dir(mock_home_env):
test_config = {}
config = config_loader.add_default_values_to_config(test_config)
assert "data_dir" in config
assert config["data_dir"] == DEFAULT_DATA_DIR