Common: Add AgentConfiguration.to_mapping()
This commit is contained in:
parent
b6703becbc
commit
d62d81a795
|
@ -79,6 +79,16 @@ class AgentConfiguration:
|
||||||
except MarshmallowError as err:
|
except MarshmallowError as err:
|
||||||
raise InvalidConfigurationError(str(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
|
@staticmethod
|
||||||
def to_json(config: AgentConfiguration) -> str:
|
def to_json(config: AgentConfiguration) -> str:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -178,13 +178,10 @@ def test_incorrect_type():
|
||||||
AgentConfiguration(**valid_config_dict)
|
AgentConfiguration(**valid_config_dict)
|
||||||
|
|
||||||
|
|
||||||
def test_from_dict():
|
def test_to_from_mapping():
|
||||||
schema = AgentConfigurationSchema()
|
config = AgentConfiguration.from_mapping(AGENT_CONFIGURATION)
|
||||||
dict_ = deepcopy(AGENT_CONFIGURATION)
|
|
||||||
|
|
||||||
config = AgentConfiguration.from_mapping(dict_)
|
assert AgentConfiguration.to_mapping(config) == AGENT_CONFIGURATION
|
||||||
|
|
||||||
assert schema.dump(config) == dict_
|
|
||||||
|
|
||||||
|
|
||||||
def test_from_dict__invalid_data():
|
def test_from_dict__invalid_data():
|
||||||
|
|
Loading…
Reference in New Issue