forked from p15670423/monkey
Common: Add AgentConfiguration.to_json()
This commit is contained in:
parent
1f9a056b0b
commit
28250daffe
|
@ -1,3 +1,5 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
@ -32,6 +34,10 @@ class AgentConfiguration:
|
||||||
def from_json(config_json: dict):
|
def from_json(config_json: dict):
|
||||||
return AgentConfigurationSchema().loads(config_json)
|
return AgentConfigurationSchema().loads(config_json)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def to_json(config: AgentConfiguration) -> str:
|
||||||
|
return AgentConfigurationSchema().dumps(config)
|
||||||
|
|
||||||
|
|
||||||
class AgentConfigurationSchema(Schema):
|
class AgentConfigurationSchema(Schema):
|
||||||
keep_tunnel_open_time = fields.Float()
|
keep_tunnel_open_time = fields.Float()
|
||||||
|
|
|
@ -198,3 +198,11 @@ def test_from_json():
|
||||||
config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON)
|
config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON)
|
||||||
|
|
||||||
assert schema.dump(config) == dict_
|
assert schema.dump(config) == dict_
|
||||||
|
|
||||||
|
|
||||||
|
def test_to_json():
|
||||||
|
config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON)
|
||||||
|
|
||||||
|
assert json.loads(AgentConfiguration.to_json(config)) == json.loads(
|
||||||
|
DEFAULT_AGENT_CONFIGURATION_JSON
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue