Skip to content

Commit

Permalink
fix: add unit tests for group logging function
Browse files Browse the repository at this point in the history
  • Loading branch information
gcharest authored Jun 12, 2024
1 parent a3022b9 commit 03f04c6
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions app/tests/modules/provisioning/test_provisioning_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from modules.provisioning import entities


@patch("modules.provisioning.entities.log_to_sentinel")
@patch("modules.provisioning.entities.logger")
def test_provision_entities_success(mock_logger):
def test_provision_entities_success(mock_logger, mock_log_to_sentinel):
users_list = [{"name": "user1"}, {"name": "user2"}, {"name": "user3"}]
mock_function = MagicMock()
mock_function.return_value = True
Expand All @@ -28,10 +29,12 @@ def test_provision_entities_success(mock_logger):

assert mock_logger.info.call_args_list == info_calls
mock_logger.error.assert_not_called()
mock_log_to_sentinel.assert_called()


@patch("modules.provisioning.entities.log_to_sentinel")
@patch("modules.provisioning.entities.logger")
def test_provision_entities_failure(mock_logger):
def test_provision_entities_failure(mock_logger, mock_log_to_sentinel):
mock_function = MagicMock()
users_list = [{"name": "user1"}, {"name": "user2"}, {"name": "user3"}]
mock_function.side_effect = [True, False, True]
Expand All @@ -58,10 +61,12 @@ def test_provision_entities_failure(mock_logger):
assert mock_logger.error.call_args_list == [
call("aws:Entity:creation:Failed: user2"),
]
mock_log_to_sentinel.assert_called()


@patch("modules.provisioning.entities.log_to_sentinel")
@patch("modules.provisioning.entities.logger")
def test_provision_entities_empty_list(mock_logger):
def test_provision_entities_empty_list(mock_logger, mock_log_to_sentinel):
users_list = []
mock_function = MagicMock()
result = entities.provision_entities(
Expand All @@ -79,3 +84,35 @@ def test_provision_entities_empty_list(mock_logger):
in mock_logger.info.call_args_list
)
mock_logger.error.assert_not_called()
mock_log_to_sentinel.assert_not_called()


@patch("modules.provisioning.entities.log_to_sentinel")
@patch("modules.provisioning.entities.logger")
def test_provision_entities_execute_false(mock_logger, mock_log_to_sentinel):
mock_function = MagicMock()
users_list = [{"name": "user1"}, {"name": "user2"}, {"name": "user3"}]
mock_function.side_effect = [True, True, True]

result = entities.provision_entities(
mock_function,
users_list,
execute=False,
integration_name="aws",
operation_name="creation",
display_key="name",
)

assert len(result) == 3
assert mock_function.call_count == 0

info_calls = [
call("aws:Entity:creation: Started processing 3 entities"),
call("aws:Entity:creation:Successful:DRY_RUN: user1"),
call("aws:Entity:creation:Successful:DRY_RUN: user2"),
call("aws:Entity:creation:Successful:DRY_RUN: user3"),
call("aws:Entity:creation: Completed processing 3 entities"),
]

assert mock_logger.info.call_args_list == info_calls
mock_log_to_sentinel.assert_called()

0 comments on commit 03f04c6

Please sign in to comment.