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