From df5cec63236db71dcf60dac40f9bc3c0cb43ad94 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Thu, 20 May 2021 13:51:52 +0300 Subject: [PATCH] Added a simple unit test for setup_param_factory.py --- .../setup/setup_param_factory.py | 1 - .../cc/setup/test_setup_param_factory.py | 16 +++++++++++ .../monkey_island/test_config_loader.py | 27 ------------------- 3 files changed, 16 insertions(+), 28 deletions(-) create mode 100644 monkey/tests/unit_tests/monkey_island/cc/setup/test_setup_param_factory.py delete mode 100644 monkey/tests/unit_tests/monkey_island/test_config_loader.py diff --git a/monkey/monkey_island/setup/setup_param_factory.py b/monkey/monkey_island/setup/setup_param_factory.py index 0c0fe8881..32b1b60db 100644 --- a/monkey/monkey_island/setup/setup_param_factory.py +++ b/monkey/monkey_island/setup/setup_param_factory.py @@ -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 diff --git a/monkey/tests/unit_tests/monkey_island/cc/setup/test_setup_param_factory.py b/monkey/tests/unit_tests/monkey_island/cc/setup/test_setup_param_factory.py new file mode 100644 index 000000000..d8ea9692e --- /dev/null +++ b/monkey/tests/unit_tests/monkey_island/cc/setup/test_setup_param_factory.py @@ -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" diff --git a/monkey/tests/unit_tests/monkey_island/test_config_loader.py b/monkey/tests/unit_tests/monkey_island/test_config_loader.py deleted file mode 100644 index 20c330f6a..000000000 --- a/monkey/tests/unit_tests/monkey_island/test_config_loader.py +++ /dev/null @@ -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