UT: Add status code tests for HTTIslandAPIClient

This commit is contained in:
Ilija Lazoroski 2022-09-20 08:50:55 +02:00
parent 0c13298bbb
commit 1b4f834f46
1 changed files with 51 additions and 0 deletions

View File

@ -6,6 +6,8 @@ from infection_monkey.island_api_client import (
HTTPIslandAPIClient,
IslandAPIConnectionError,
IslandAPIError,
IslandAPIRequestError,
IslandAPIRequestFailedError,
IslandAPITimeoutError,
)
@ -33,6 +35,21 @@ def test_island_api_client(actual_error, expected_error):
HTTPIslandAPIClient(SERVER)
@pytest.mark.parametrize(
"status_code, expected_error",
[
(401, IslandAPIRequestError),
(501, IslandAPIRequestFailedError),
],
)
def test_island_api_client__status_code(status_code, expected_error):
with requests_mock.Mocker() as m:
m.get(ISLAND_URI, status_code=status_code)
with pytest.raises(expected_error):
HTTPIslandAPIClient(SERVER)
@pytest.mark.parametrize(
"actual_error, expected_error",
[
@ -51,6 +68,23 @@ def test_island_api_client__send_log(actual_error, expected_error):
island_api_client.send_log(log_contents="some_data")
@pytest.mark.parametrize(
"status_code, expected_error",
[
(401, IslandAPIRequestError),
(501, IslandAPIRequestFailedError),
],
)
def test_island_api_client_send_log__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.post(ISLAND_SEND_LOG_URI, status_code=status_code)
island_api_client.send_log(log_contents="some_data")
@pytest.mark.parametrize(
"actual_error, expected_error",
[
@ -67,3 +101,20 @@ def test_island_api_client__get_pba_file(actual_error, expected_error):
with pytest.raises(expected_error):
m.get(ISLAND_GET_PBA_FILE_URI, exc=actual_error)
island_api_client.get_pba_file(filename=PBA_FILE)
@pytest.mark.parametrize(
"status_code, expected_error",
[
(401, IslandAPIRequestError),
(501, IslandAPIRequestFailedError),
],
)
def test_island_api_client_get_pba_file__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_PBA_FILE_URI, status_code=status_code)
island_api_client.get_pba_file(filename=PBA_FILE)