Skip to content

Commit

Permalink
Adding logic that the security team does not get automatically added …
Browse files Browse the repository at this point in the history
…when we are testing creating an incident
  • Loading branch information
sylviamclaughlin authored Apr 11, 2024
1 parent 26d9c0e commit a8ff860
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/modules/incident/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ def submit(ack, view, say, body, client, logger):

# Get users from the @security group
response = client.usergroups_users_list(usergroup=SLACK_SECURITY_USER_GROUP_ID)
if response.get("ok"):

# if we are testing, ie PREFIX is "dev" then don't add the security group users since we don't want to spam them
if response.get("ok") and PREFIX == "":
for security_user in response["users"]:
if security_user != user_id:
users_to_invite.append(security_user)
Expand Down
57 changes: 57 additions & 0 deletions app/tests/modules/incident/test_incident.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime

import os

from modules import incident

from unittest.mock import call, MagicMock, patch, ANY
Expand Down Expand Up @@ -875,6 +877,61 @@ def test_incident_submit_does_not_invite_security_group_members_already_in_chann
)


@patch("modules.incident.incident.google_drive.update_incident_list")
@patch("modules.incident.incident.google_drive.merge_data")
@patch("modules.incident.incident.google_drive.create_new_incident")
@patch("modules.incident.incident.google_drive.list_metadata")
@patch("modules.incident.incident.opsgenie.get_on_call_users")
@patch("modules.incident.incident.log_to_sentinel")
@patch.dict(os.environ, {"PREFIX": "dev"})
def test_incident_submit_does_not_invite_security_group_members_if_prefix_dev(
_log_to_sentinel_mock,
mock_get_on_call_users,
mock_list_metadata,
mock_create_new_incident,
mock_merge_data,
mock_update_incident_list,
):
ack = MagicMock()
logger = MagicMock()
view = helper_generate_view()
say = MagicMock()
body = {"user": {"id": "creator_user_id"}, "trigger_id": "trigger_id", "view": view}
client = MagicMock()
client.conversations_create.return_value = {
"channel": {"id": "channel_id", "name": "channel_name"}
}
client.users_lookupByEmail.return_value = {
"ok": True,
"user": {
"id": "on_call_user_id",
"profile": {"display_name_normalized": "name"},
},
}
client.usergroups_users_list.return_value = {
"ok": True,
"users": [
"creator_user_id",
],
}

mock_create_new_incident.return_value = "id"

mock_get_on_call_users.return_value = ["email"]
mock_list_metadata.return_value = {"appProperties": {"genie_schedule": "oncall"}}

incident.submit(ack, view, say, body, client, logger)
mock_get_on_call_users.assert_called_once_with("oncall")
client.users_lookupByEmail.assert_any_call(email="email")
client.usergroups_users_list(usergroup="SLACK_SECURITY_USER_GROUP_ID")
client.conversations_invite.assert_has_calls(
[
call(channel="channel_id", users="creator_user_id"),
call(channel="channel_id", users=["on_call_user_id"]),
]
)


@patch("integrations.google_workspace.google_docs.extract_google_doc_id")
def test_handle_reaction_added_floppy_disk_reaction_in_incident_channel(
mock_extract_google_doc_id,
Expand Down

0 comments on commit a8ff860

Please sign in to comment.