forked from p15670423/monkey
Island: Publish IslandEventTopic.CLEAR_SIMULATION_DATA from resource
This commit is contained in:
parent
2c750acc7a
commit
ba724db969
|
@ -2,16 +2,16 @@ from http import HTTPStatus
|
|||
|
||||
from flask import make_response
|
||||
|
||||
from monkey_island.cc.event_queue import IIslandEventQueue, IslandEventTopic
|
||||
from monkey_island.cc.resources.AbstractResource import AbstractResource
|
||||
from monkey_island.cc.resources.request_authentication import jwt_required
|
||||
from monkey_island.cc.services import RepositoryService
|
||||
|
||||
|
||||
class ClearSimulationData(AbstractResource):
|
||||
urls = ["/api/clear-simulation-data"]
|
||||
|
||||
def __init__(self, repository_service: RepositoryService):
|
||||
self._repository_service = repository_service
|
||||
def __init__(self, island_event_queue: IIslandEventQueue):
|
||||
self._island_event_queue = island_event_queue
|
||||
|
||||
@jwt_required
|
||||
def post(self):
|
||||
|
@ -19,5 +19,5 @@ class ClearSimulationData(AbstractResource):
|
|||
Clear all data collected during the simulation
|
||||
"""
|
||||
|
||||
self._repository_service.clear_simulation_data()
|
||||
self._island_event_queue.publish(IslandEventTopic.CLEAR_SIMULATION_DATA)
|
||||
return make_response({}, HTTPStatus.NO_CONTENT)
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
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 ClearSimulationData
|
||||
|
||||
|
||||
@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_clear_simulation_data(flask_client, mock_island_event_queue):
|
||||
resp = flask_client.post(ClearSimulationData.urls[0], follow_redirects=True)
|
||||
|
||||
assert resp.status_code == HTTPStatus.NO_CONTENT
|
||||
mock_island_event_queue.publish.assert_called_once_with(IslandEventTopic.CLEAR_SIMULATION_DATA)
|
Loading…
Reference in New Issue