From 1b1bc85804b13bb2c1fe586239586ae141834f98 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 22 Jul 2022 11:49:54 -0400 Subject: [PATCH] UT: Fix false negative in test_agent_configuration_endpoint() --- .../cc/resources/test_agent_configuration.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_agent_configuration.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_agent_configuration.py index 874500b81..43d403eed 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/test_agent_configuration.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_agent_configuration.py @@ -6,8 +6,13 @@ from tests.common.example_agent_configuration import AGENT_CONFIGURATION from tests.monkey_island import InMemoryAgentConfigurationRepository from tests.unit_tests.monkey_island.conftest import get_url_for_resource +from common.configuration import AgentConfiguration from monkey_island.cc.repository import IAgentConfigurationRepository -from monkey_island.cc.resources.agent_configuration import AgentConfiguration +from monkey_island.cc.resources.agent_configuration import ( + AgentConfiguration as AgentConfigurationResource, +) + +AGENT_CONFIGURATION_URL = get_url_for_resource(AgentConfigurationResource) @pytest.fixture @@ -21,30 +26,27 @@ def flask_client(build_flask_client): def test_agent_configuration_endpoint(flask_client): - agent_configuration_url = get_url_for_resource(AgentConfiguration) - - flask_client.post( - agent_configuration_url, data=json.dumps(AGENT_CONFIGURATION), follow_redirects=True + resp = flask_client.post( + AGENT_CONFIGURATION_URL, + data=AgentConfiguration.to_json(AGENT_CONFIGURATION), + follow_redirects=True, ) - resp = flask_client.get(agent_configuration_url) + assert resp.status_code == 200 + resp = flask_client.get(AGENT_CONFIGURATION_URL) assert resp.status_code == 200 assert json.loads(resp.data) == AGENT_CONFIGURATION def test_agent_configuration_invalid_config(flask_client): - agent_configuration_url = get_url_for_resource(AgentConfiguration) - resp = flask_client.post( - agent_configuration_url, data=json.dumps({"invalid_config": "invalid_stuff"}) + AGENT_CONFIGURATION_URL, data=json.dumps({"invalid_config": "invalid_stuff"}) ) assert resp.status_code == 400 def test_agent_configuration_invalid_json(flask_client): - agent_configuration_url = get_url_for_resource(AgentConfiguration) - - resp = flask_client.post(agent_configuration_url, data="InvalidJson!") + resp = flask_client.post(AGENT_CONFIGURATION_URL, data="InvalidJson!") assert resp.status_code == 400