From 90259c1b7a8264bf107199240592d167793ad533 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 27 Jun 2022 07:07:53 -0400 Subject: [PATCH] UT: Remove dependency on DEFAULT_AGENT_CONFIGURATION_JSON --- .../configuration/test_agent_configuration.py | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) 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 4b264c8cb..e06a4cf3e 100644 --- a/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py +++ b/monkey/tests/unit_tests/common/configuration/test_agent_configuration.py @@ -1,4 +1,5 @@ import json +from copy import deepcopy import pytest from tests.common.example_agent_configuration import ( @@ -26,11 +27,7 @@ from tests.common.example_agent_configuration import ( WINDOWS_FILENAME, ) -from common.configuration import ( - DEFAULT_AGENT_CONFIGURATION_JSON, - AgentConfiguration, - InvalidConfigurationError, -) +from common.configuration import AgentConfiguration, InvalidConfigurationError from common.configuration.agent_configuration import AgentConfigurationSchema from common.configuration.agent_sub_configuration_schemas import ( CustomPBAConfigurationSchema, @@ -182,15 +179,9 @@ def test_incorrect_type(): AgentConfiguration(**valid_config_dict) -def test_default_agent_configuration(): - config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON) - - assert isinstance(config, AgentConfiguration) - - def test_from_dict(): schema = AgentConfigurationSchema() - dict_ = json.loads(DEFAULT_AGENT_CONFIGURATION_JSON) + dict_ = deepcopy(AGENT_CONFIGURATION) config = AgentConfiguration.from_mapping(dict_) @@ -198,7 +189,7 @@ def test_from_dict(): def test_from_dict__invalid_data(): - dict_ = json.loads(DEFAULT_AGENT_CONFIGURATION_JSON) + dict_ = deepcopy(AGENT_CONFIGURATION) dict_["payloads"] = "payloads" with pytest.raises(InvalidConfigurationError): @@ -207,15 +198,16 @@ def test_from_dict__invalid_data(): def test_from_json(): schema = AgentConfigurationSchema() - dict_ = json.loads(DEFAULT_AGENT_CONFIGURATION_JSON) + dict_ = deepcopy(AGENT_CONFIGURATION) - config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON) + config = AgentConfiguration.from_json(json.dumps(dict_)) + assert isinstance(config, AgentConfiguration) assert schema.dump(config) == dict_ def test_from_json__invalid_data(): - invalid_dict = json.loads(DEFAULT_AGENT_CONFIGURATION_JSON) + invalid_dict = deepcopy(AGENT_CONFIGURATION) invalid_dict["payloads"] = "payloads" with pytest.raises(InvalidConfigurationError): @@ -223,8 +215,6 @@ def test_from_json__invalid_data(): def test_to_json(): - config = AgentConfiguration.from_json(DEFAULT_AGENT_CONFIGURATION_JSON) + config = deepcopy(AGENT_CONFIGURATION) - assert json.loads(AgentConfiguration.to_json(config)) == json.loads( - DEFAULT_AGENT_CONFIGURATION_JSON - ) + assert json.loads(AgentConfiguration.to_json(config)) == AGENT_CONFIGURATION