From d62d81a7955a3eefa80192b3e0f5ab0a17f62dcf Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 22 Jul 2022 12:03:55 -0400 Subject: [PATCH] Common: Add AgentConfiguration.to_mapping() --- monkey/common/configuration/agent_configuration.py | 10 ++++++++++ .../common/configuration/test_agent_configuration.py | 9 +++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/monkey/common/configuration/agent_configuration.py b/monkey/common/configuration/agent_configuration.py index d6e61ddd1..081bfa793 100644 --- a/monkey/common/configuration/agent_configuration.py +++ b/monkey/common/configuration/agent_configuration.py @@ -79,6 +79,16 @@ class AgentConfiguration: except MarshmallowError as err: raise InvalidConfigurationError(str(err)) + @staticmethod + def to_mapping(config: AgentConfiguration) -> Mapping[str, Any]: + """ + Serialize an AgentConfiguration to a Mapping + + :param config: An AgentConfiguration + :return: A Mapping that represents the AgentConfiguration + """ + return AgentConfigurationSchema().dump(config) + @staticmethod def to_json(config: AgentConfiguration) -> str: """ diff --git a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py index fecb6a6f6..622c9f5df 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -178,13 +178,10 @@ def test_incorrect_type(): AgentConfiguration(**valid_config_dict) -def test_from_dict(): - schema = AgentConfigurationSchema() - dict_ = deepcopy(AGENT_CONFIGURATION) +def test_to_from_mapping(): + config = AgentConfiguration.from_mapping(AGENT_CONFIGURATION) - config = AgentConfiguration.from_mapping(dict_) - - assert schema.dump(config) == dict_ + assert AgentConfiguration.to_mapping(config) == AGENT_CONFIGURATION def test_from_dict__invalid_data():