UT: Rename `convert_lists_to_tuples` -> `convert_all_lists_to_tuples_in_mapping`

This commit is contained in:
Shreya Malviya 2022-08-30 23:07:29 +05:30
parent 82d8f5bacd
commit 4f599c3118
3 changed files with 10 additions and 10 deletions

View File

@ -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():

View File

@ -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):

View File

@ -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