forked from p34709852/monkey
UT: Add test for get_config
This commit is contained in:
parent
fd08212763
commit
4c3a1ba89a
|
@ -40,6 +40,7 @@ ISLAND_GET_AGENT_BINARY_URI = f"https://{SERVER}/api/agent-binaries/{WINDOWS}"
|
|||
ISLAND_SEND_EVENTS_URI = f"https://{SERVER}/api/agent-events"
|
||||
ISLAND_REGISTER_AGENT_URI = f"https://{SERVER}/api/agents"
|
||||
ISLAND_AGENT_STOP_URI = f"https://{SERVER}/api/monkey-control/needs-to-stop/{AGENT_ID}"
|
||||
ISLAND_GET_CONFIG_URI = f"https://{SERVER}/api/agent-configuration"
|
||||
|
||||
|
||||
class Event1(AbstractAgentEvent):
|
||||
|
@ -363,3 +364,47 @@ def test_island_api_client_should_agent_stop__bad_json():
|
|||
with pytest.raises(IslandAPIRequestFailedError):
|
||||
m.get(ISLAND_AGENT_STOP_URI, content=b"bad")
|
||||
island_api_client.should_agent_stop(AGENT_ID)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"actual_error, expected_error",
|
||||
[
|
||||
(requests.exceptions.ConnectionError, IslandAPIConnectionError),
|
||||
(TimeoutError, IslandAPITimeoutError),
|
||||
],
|
||||
)
|
||||
def test_island_api_client__get_config(actual_error, expected_error):
|
||||
with requests_mock.Mocker() as m:
|
||||
m.get(ISLAND_URI)
|
||||
island_api_client = HTTPIslandAPIClient(SERVER)
|
||||
|
||||
with pytest.raises(expected_error):
|
||||
m.get(ISLAND_GET_CONFIG_URI, exc=actual_error)
|
||||
island_api_client.get_config()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"status_code, expected_error",
|
||||
[
|
||||
(401, IslandAPIRequestError),
|
||||
(501, IslandAPIRequestFailedError),
|
||||
],
|
||||
)
|
||||
def test_island_api_client_get_config__status_code(status_code, expected_error):
|
||||
with requests_mock.Mocker() as m:
|
||||
m.get(ISLAND_URI)
|
||||
island_api_client = HTTPIslandAPIClient(SERVER)
|
||||
|
||||
with pytest.raises(expected_error):
|
||||
m.get(ISLAND_GET_CONFIG_URI, status_code=status_code)
|
||||
island_api_client.get_config()
|
||||
|
||||
|
||||
def test_island_api_client_get_config__bad_json():
|
||||
with requests_mock.Mocker() as m:
|
||||
m.get(ISLAND_URI)
|
||||
island_api_client = HTTPIslandAPIClient(SERVER)
|
||||
|
||||
with pytest.raises(IslandAPIRequestFailedError):
|
||||
m.get(ISLAND_GET_CONFIG_URI, content=b"bad")
|
||||
island_api_client.get_config()
|
||||
|
|
Loading…
Reference in New Issue