From f944347644d8b1e0069d4d376667783cddf4951b Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Tue, 13 Sep 2022 11:41:08 +0200 Subject: [PATCH] UT: Test ResetAgentConfiguration endpoint --- .../test_reset_agent_configuration.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 monkey/tests/unit_tests/monkey_island/cc/resources/test_reset_agent_configuration.py diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/test_reset_agent_configuration.py b/monkey/tests/unit_tests/monkey_island/cc/resources/test_reset_agent_configuration.py new file mode 100644 index 000000000..c89cb372b --- /dev/null +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/test_reset_agent_configuration.py @@ -0,0 +1,31 @@ +from http import HTTPStatus +from unittest.mock import MagicMock + +import pytest +from tests.common import StubDIContainer + +from monkey_island.cc.event_queue import IIslandEventQueue, IslandEventTopic +from monkey_island.cc.resources import ResetAgentConfiguration + + +@pytest.fixture +def mock_island_event_queue() -> IIslandEventQueue: + return MagicMock(spec=IIslandEventQueue) + + +@pytest.fixture +def flask_client(build_flask_client, mock_island_event_queue): + container = StubDIContainer() + container.register_instance(IIslandEventQueue, mock_island_event_queue) + + with build_flask_client(container) as flask_client: + yield flask_client + + +def test_reset_agent_configuration(flask_client, mock_island_event_queue): + resp = flask_client.post(ResetAgentConfiguration.urls[0], follow_redirects=True) + + assert resp.status_code == HTTPStatus.OK + mock_island_event_queue.publish.assert_called_once_with( + IslandEventTopic.RESET_AGENT_CONFIGURATION + )