From 4f599c311827d4d69408a466628a9dceb2b0779a Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 30 Aug 2022 23:07:29 +0530 Subject: [PATCH] UT: Rename `convert_lists_to_tuples` -> `convert_all_lists_to_tuples_in_mapping` --- .../agent_configuration/test_agent_configuration.py | 8 ++++---- .../cc/resources/test_agent_configuration.py | 8 ++++---- monkey/tests/utils.py | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/monkey/tests/unit_tests/common/agent_configuration/test_agent_configuration.py b/monkey/tests/unit_tests/common/agent_configuration/test_agent_configuration.py index cb561aac5..15e768556 100644 --- a/monkey/tests/unit_tests/common/agent_configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/agent_configuration/test_agent_configuration.py @@ -23,7 +23,7 @@ from tests.common.example_agent_configuration import ( WINDOWS_COMMAND, WINDOWS_FILENAME, ) -from tests.utils import convert_lists_to_tuples +from tests.utils import convert_all_lists_to_tuples_in_mapping from common.agent_configuration.agent_configuration import AgentConfiguration from common.agent_configuration.agent_sub_configurations import ( @@ -181,7 +181,7 @@ def test_exploitation_configuration(): config_dict = config.dict() assert isinstance(config, ExploitationConfiguration) - assert config_dict == convert_lists_to_tuples(EXPLOITATION_CONFIGURATION.copy()) + assert config_dict == convert_all_lists_to_tuples_in_mapping(EXPLOITATION_CONFIGURATION.copy()) def test_propagation_configuration(): @@ -192,7 +192,7 @@ def test_propagation_configuration(): assert isinstance(config.network_scan, NetworkScanConfiguration) assert isinstance(config.exploitation, ExploitationConfiguration) assert config.maximum_depth == 5 - assert config_dict == convert_lists_to_tuples(PROPAGATION_CONFIGURATION.copy()) + assert config_dict == convert_all_lists_to_tuples_in_mapping(PROPAGATION_CONFIGURATION.copy()) def test_propagation_configuration__invalid_maximum_depth(): @@ -214,7 +214,7 @@ def test_agent_configuration(): assert isinstance(config.credential_collectors[0], PluginConfiguration) assert isinstance(config.payloads[0], PluginConfiguration) assert isinstance(config.propagation, PropagationConfiguration) - assert config_dict == convert_lists_to_tuples(AGENT_CONFIGURATION.copy()) + assert config_dict == convert_all_lists_to_tuples_in_mapping(AGENT_CONFIGURATION.copy()) def test_agent_configuration__negative_keep_tunnel_open_time(): diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_agent_configuration.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_agent_configuration.py index 9845405c8..f3a8abdb0 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_agent_configuration.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_agent_configuration.py @@ -5,7 +5,7 @@ from tests.common import StubDIContainer from tests.common.example_agent_configuration import AGENT_CONFIGURATION from tests.monkey_island import InMemoryAgentConfigurationRepository from tests.unit_tests.monkey_island.conftest import get_url_for_resource -from tests.utils import convert_lists_to_tuples +from tests.utils import convert_all_lists_to_tuples_in_mapping from common.agent_configuration import AgentConfiguration from monkey_island.cc.repository import IAgentConfigurationRepository @@ -35,9 +35,9 @@ def test_agent_configuration_endpoint(flask_client): assert resp.status_code == 200 - assert convert_lists_to_tuples(json.loads(resp.data)) == convert_lists_to_tuples( - AGENT_CONFIGURATION.copy() - ) + assert convert_all_lists_to_tuples_in_mapping( + json.loads(resp.data) + ) == convert_all_lists_to_tuples_in_mapping(AGENT_CONFIGURATION.copy()) def test_agent_configuration_invalid_config(flask_client): diff --git a/monkey/tests/utils.py b/monkey/tests/utils.py index d2a9113ae..1211e72bc 100644 --- a/monkey/tests/utils.py +++ b/monkey/tests/utils.py @@ -35,11 +35,11 @@ def add_files_to_dir(parent_dir: Path, file_names: Iterable[str]) -> Iterable[Pa # This is only needed since values are compared in configuration objects in the tests. # In practice, the list/tuple differences shouldn't make any difference since both are iterable. -def convert_lists_to_tuples(configuration: Mapping): +def convert_all_lists_to_tuples_in_mapping(configuration: Mapping): for key in configuration: value = configuration[key] if isinstance(value, list): configuration[key] = tuple(value) if isinstance(value, Mapping): - convert_lists_to_tuples(value) + convert_all_lists_to_tuples_in_mapping(value) return configuration