From e4eee6a5eb692255c4ba6e543601c226eb725eac Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 24 Jun 2022 12:23:37 -0400 Subject: [PATCH] UT: Use from_dict() and from_json() in tests --- .../tests/data_for_tests/monkey_configs/default_config.py | 4 ++-- .../in_memory_agent_configuration_repository.py | 4 ++-- .../common/configuration/test_agent_configuration.py | 6 ++---- .../repository/test_file_agent_configuration_repository.py | 5 ++--- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/monkey/tests/data_for_tests/monkey_configs/default_config.py b/monkey/tests/data_for_tests/monkey_configs/default_config.py index e232d122d..6c0771af0 100644 --- a/monkey/tests/data_for_tests/monkey_configs/default_config.py +++ b/monkey/tests/data_for_tests/monkey_configs/default_config.py @@ -1,4 +1,4 @@ -from common.configuration import AgentConfigurationSchema +from common.configuration import AgentConfiguration flat_config = { "keep_tunnel_open_time": 30, @@ -116,4 +116,4 @@ flat_config = { }, } -DEFAULT_CONFIG = AgentConfigurationSchema().load(flat_config) +DEFAULT_CONFIG = AgentConfiguration.from_dict(flat_config) diff --git a/monkey/tests/monkey_island/in_memory_agent_configuration_repository.py b/monkey/tests/monkey_island/in_memory_agent_configuration_repository.py index e737d645c..b18465568 100644 --- a/monkey/tests/monkey_island/in_memory_agent_configuration_repository.py +++ b/monkey/tests/monkey_island/in_memory_agent_configuration_repository.py @@ -1,12 +1,12 @@ from tests.common.example_agent_configuration import AGENT_CONFIGURATION -from common.configuration.agent_configuration import AgentConfigurationSchema +from common.configuration.agent_configuration import AgentConfiguration from monkey_island.cc.repository import IAgentConfigurationRepository class InMemoryAgentConfigurationRepository(IAgentConfigurationRepository): def __init__(self): - self._configuration = AgentConfigurationSchema().load(AGENT_CONFIGURATION) + self._configuration = AgentConfiguration.from_dict(AGENT_CONFIGURATION) def get_configuration(self): return self._configuration 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 134a18a91..23830d619 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -161,7 +161,7 @@ def test_propagation_configuration(): def test_agent_configuration(): schema = AgentConfigurationSchema() - config = schema.load(AGENT_CONFIGURATION) + config = AgentConfiguration.from_dict(AGENT_CONFIGURATION) config_dict = schema.dump(config) assert isinstance(config, AgentConfiguration) @@ -175,9 +175,7 @@ def test_agent_configuration(): def test_default_agent_configuration(): - schema = AgentConfigurationSchema() - - config = schema.loads(DEFAULT_AGENT_CONFIGURATION_JSON) + config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON) assert isinstance(config, AgentConfiguration) diff --git a/monkey/tests/unit_tests/monkey_island/cc/repository/test_file_agent_configuration_repository.py b/monkey/tests/unit_tests/monkey_island/cc/repository/test_file_agent_configuration_repository.py index 4ab111606..21dc4503b 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/repository/test_file_agent_configuration_repository.py +++ b/monkey/tests/unit_tests/monkey_island/cc/repository/test_file_agent_configuration_repository.py @@ -2,7 +2,7 @@ import pytest from tests.common.example_agent_configuration import AGENT_CONFIGURATION from tests.monkey_island import OpenErrorFileRepository, SingleFileRepository -from common.configuration import AgentConfigurationSchema +from common.configuration import AgentConfiguration from monkey_island.cc.repository import FileAgentConfigurationRepository, RetrievalError @@ -12,8 +12,7 @@ def repository(default_agent_configuration): def test_store_agent_config(repository): - schema = AgentConfigurationSchema() - agent_configuration = schema.load(AGENT_CONFIGURATION) + agent_configuration = AgentConfiguration.from_dict(AGENT_CONFIGURATION) repository.store_configuration(agent_configuration) retrieved_agent_configuration = repository.get_configuration()