UT: Add tests for AgentConfiguration resource

This commit is contained in:
Ilija Lazoroski 2022-06-23 14:31:51 +02:00 committed by Shreya Malviya
parent b35832b9dd
commit d7329ea839
1 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,50 @@
import json
import pytest
from tests.common import StubDIContainer
from tests.common.example_agent_configuration import AGENT_CONFIGURATION
from tests.monkey_island import InMemoryFileAgentConfigurationRepository
from tests.unit_tests.monkey_island.conftest import get_url_for_resource
from monkey_island.cc.repository import IAgentConfigurationRepository
from monkey_island.cc.resources.agent_configuration import AgentConfiguration
@pytest.fixture
def flask_client(build_flask_client):
container = StubDIContainer()
container.register(IAgentConfigurationRepository, InMemoryFileAgentConfigurationRepository)
with build_flask_client(container) as flask_client:
yield 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.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"})
)
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!")
assert resp.status_code == 400