Common: Add AgentConfiguration.to_mapping()

This commit is contained in:
Mike Salvatore 2022-07-22 12:03:55 -04:00
parent b6703becbc
commit d62d81a795
2 changed files with 13 additions and 6 deletions

View File

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

View File

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