Refactored tests to test config file parsing and IslandConfig param extraction
This commit is contained in:
parent
9cffb9e9d1
commit
2621458b37
|
@ -0,0 +1,2 @@
|
|||
{
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
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"
|
|
@ -9,5 +9,10 @@ def server_configs_dir(data_for_tests_dir):
|
|||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def test_server_config(server_configs_dir):
|
||||
return os.path.join(server_configs_dir, "test_server_config.json")
|
||||
def server_config_init_only(server_configs_dir):
|
||||
return os.path.join(server_configs_dir, "server_config_init_only.json")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def server_config_empty(server_configs_dir):
|
||||
return os.path.join(server_configs_dir, "server_config_empty.json")
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
from monkey_island import config_file_parser
|
||||
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR, DEFAULT_LOG_LEVEL
|
||||
|
||||
|
||||
def test_load_server_config_from_file(test_server_config):
|
||||
config = config_file_parser.load_server_config_from_file(test_server_config)
|
||||
def test_load_server_config_from_file(server_config_init_only):
|
||||
config = config_file_parser.load_island_config_from_file(server_config_init_only)
|
||||
|
||||
assert config["data_dir"] == "~/.monkey_island"
|
||||
assert config["log_level"] == "NOTICE"
|
||||
assert config.data_dir == "~/.monkey_island"
|
||||
assert config.log_level == "NOTICE"
|
||||
|
||||
|
||||
def test_load_server_config_from_file_default_path(monkeypatch, test_server_config):
|
||||
monkeypatch.setattr(config_file_parser, "DEFAULT_SERVER_CONFIG_PATH", test_server_config)
|
||||
config = config_file_parser.load_server_config_from_file("")
|
||||
def test_load_server_config_from_file_empty_file(monkeypatch, server_config_empty):
|
||||
config = config_file_parser.load_island_config_from_file(server_config_empty)
|
||||
|
||||
assert config["data_dir"] == "~/.monkey_island"
|
||||
assert config["log_level"] == "NOTICE"
|
||||
assert config.data_dir == DEFAULT_DATA_DIR
|
||||
assert config.log_level == DEFAULT_LOG_LEVEL
|
||||
|
|
Loading…
Reference in New Issue