From 5847674d9209122bf42f9259d08b78d8cf9dd5e4 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 11 May 2021 13:14:07 -0400 Subject: [PATCH] island: Add unit test for load_server_config() --- monkey/tests/conftest.py | 17 +++++++++++++++++ .../tests/monkey_island/test_config_loader.py | 10 ++++++++++ .../server_configs/test_server_config.json | 4 ++++ 3 files changed, 31 insertions(+) create mode 100644 monkey/tests/monkey_island/test_config_loader.py create mode 100644 monkey/tests/resources/server_configs/test_server_config.json diff --git a/monkey/tests/conftest.py b/monkey/tests/conftest.py index 81806ef69..328cb109c 100644 --- a/monkey/tests/conftest.py +++ b/monkey/tests/conftest.py @@ -46,3 +46,20 @@ def with_data_dir(environment_resources_dir): @pytest.fixture(scope="session") def with_data_dir_home(environment_resources_dir): return os.path.join(environment_resources_dir, "server_config_with_data_dir_home.json") + + +@pytest.fixture(scope="session") +def server_config_resources_dir(resources_dir): + return os.path.join(resources_dir, "server_configs") + + +@pytest.fixture(scope="session") +def test_server_config(server_config_resources_dir): + return os.path.join(server_config_resources_dir, "test_server_config.json") + + +@pytest.fixture +def mock_home_env(monkeypatch, tmpdir): + monkeypatch.setenv("HOME", str(tmpdir)) + + return tmpdir diff --git a/monkey/tests/monkey_island/test_config_loader.py b/monkey/tests/monkey_island/test_config_loader.py new file mode 100644 index 000000000..ac2e35377 --- /dev/null +++ b/monkey/tests/monkey_island/test_config_loader.py @@ -0,0 +1,10 @@ +import os + +from monkey_island import config_loader + + +def test_load_server_config_from_file(test_server_config, mock_home_env): + (data_dir, log_level) = config_loader.load_server_config(test_server_config) + + assert data_dir == os.path.join(mock_home_env, ".monkey_island") + assert log_level == "NOTICE" diff --git a/monkey/tests/resources/server_configs/test_server_config.json b/monkey/tests/resources/server_configs/test_server_config.json new file mode 100644 index 000000000..25082b0b3 --- /dev/null +++ b/monkey/tests/resources/server_configs/test_server_config.json @@ -0,0 +1,4 @@ +{ + "data_dir": "~/.monkey_island", + "log_level": "NOTICE" +}