generated from cds-snc/project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attach incident document to retro invite (#483)
* Adding functionality to attach the incident document to the meeting invite * Formatting
- Loading branch information
1 parent
0e1cbd0
commit fd02214
Showing
6 changed files
with
203 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,7 +154,8 @@ def test_insert_event_no_kwargs_no_delegated_email( | |
end = start | ||
emails = ["[email protected]", "[email protected]"] | ||
title = "Test Event" | ||
result = google_calendar.insert_event(start, end, emails, title) | ||
document_id = "test_document_id" | ||
result = google_calendar.insert_event(start, end, emails, title, document_id) | ||
assert result == "test_link" | ||
mock_execute_google_api_call.assert_called_once_with( | ||
"calendar", | ||
|
@@ -169,8 +170,16 @@ def test_insert_event_no_kwargs_no_delegated_email( | |
"attendees": [{"email": email.strip()} for email in emails], | ||
"summary": title, | ||
"guestsCanModify": True, | ||
"attachments": [ | ||
{ | ||
"fileUrl": f"https://docs.google.com/document/d/{document_id}", | ||
"mimeType": "application/vnd.google-apps.document", | ||
"title": "Incident Document", | ||
} | ||
], | ||
}, | ||
calendarId="primary", | ||
supportsAttachments=True, | ||
) | ||
assert not mock_convert_string_to_camel_case.called | ||
assert mock_os_environ_get.called_once_with("SRE_BOT_EMAIL") | ||
|
@@ -190,13 +199,72 @@ def test_insert_event_with_kwargs( | |
end = start | ||
emails = ["[email protected]", "[email protected]"] | ||
title = "Test Event" | ||
document_id = "test_document_id" | ||
kwargs = { | ||
"location": "Test Location", | ||
"description": "Test Description", | ||
"delegated_user_email": "test_custom_email", | ||
"time_zone": "Magic/Time_Zone", | ||
"attachments": [ | ||
{ | ||
"fileUrl": "https://docs.google.com/document/d/test_document_id", | ||
"mimeType": "application/vnd.google-apps.document", | ||
"title": "Incident Document", | ||
} | ||
], | ||
} | ||
result = google_calendar.insert_event( | ||
start, end, emails, title, document_id, **kwargs | ||
) | ||
assert result == "test_link" | ||
mock_execute_google_api_call.assert_called_once_with( | ||
"calendar", | ||
"v3", | ||
"events", | ||
"insert", | ||
scopes=["https://www.googleapis.com/auth/calendar.events"], | ||
delegated_user_email="test_custom_email", | ||
body={ | ||
"start": {"dateTime": start, "timeZone": "Magic/Time_Zone"}, | ||
"end": {"dateTime": end, "timeZone": "Magic/Time_Zone"}, | ||
"attendees": [{"email": email.strip()} for email in emails], | ||
"summary": title, | ||
"guestsCanModify": True, | ||
**kwargs, | ||
}, | ||
calendarId="primary", | ||
supportsAttachments=True, | ||
) | ||
for key in kwargs: | ||
mock_convert_string_to_camel_case.assert_any_call(key) | ||
|
||
assert not mock_os_environ_get.called | ||
|
||
|
||
@patch("os.environ.get", return_value="test_email") | ||
@patch("integrations.google_workspace.google_calendar.execute_google_api_call") | ||
@patch("integrations.google_workspace.google_calendar.convert_string_to_camel_case") | ||
def test_insert_event_with_no_document( | ||
mock_convert_string_to_camel_case, mock_execute_google_api_call, mock_os_environ_get | ||
): | ||
mock_execute_google_api_call.return_value = {"htmlLink": "test_link"} | ||
mock_convert_string_to_camel_case.side_effect = ( | ||
lambda x: x | ||
) # just return the same value | ||
start = datetime.now() | ||
end = start | ||
emails = ["[email protected]", "[email protected]"] | ||
title = "Test Event" | ||
document_id = "" | ||
kwargs = { | ||
"location": "Test Location", | ||
"description": "Test Description", | ||
"delegated_user_email": "test_custom_email", | ||
"time_zone": "Magic/Time_Zone", | ||
} | ||
result = google_calendar.insert_event(start, end, emails, title, **kwargs) | ||
result = google_calendar.insert_event( | ||
start, end, emails, title, document_id, **kwargs | ||
) | ||
assert result == "test_link" | ||
mock_execute_google_api_call.assert_called_once_with( | ||
"calendar", | ||
|
@@ -214,6 +282,7 @@ def test_insert_event_with_kwargs( | |
**kwargs, | ||
}, | ||
calendarId="primary", | ||
supportsAttachments=True, | ||
) | ||
for key in kwargs: | ||
mock_convert_string_to_camel_case.assert_any_call(key) | ||
|
@@ -237,7 +306,8 @@ def test_insert_event_api_call_error( | |
end = start | ||
emails = ["[email protected]", "[email protected]"] | ||
title = "Test Event" | ||
google_calendar.insert_event(start, end, emails, title) | ||
document_id = "test_document_id" | ||
google_calendar.insert_event(start, end, emails, title, document_id) | ||
assert ( | ||
"An unexpected error occurred in function 'insert_event': API call error" | ||
in caplog.text | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -801,6 +801,15 @@ def test_schedule_incident_retro_successful_no_bots(): | |
{"user": {"profile": {"email": "[email protected]"}}}, | ||
{"user": {"profile": {"email": "[email protected]"}}}, | ||
] | ||
mock_client.bookmarks_list.return_value = { | ||
"ok": True, | ||
"bookmarks": [ | ||
{ | ||
"title": "Incident report", | ||
"link": "https://docs.google.com/document/d/dummy_document_id/edit", | ||
} | ||
], | ||
} | ||
|
||
body = { | ||
"channel_id": "C1234567890", | ||
|
@@ -828,7 +837,11 @@ def test_schedule_incident_retro_successful_no_bots(): | |
|
||
# Verify the modal payload contains the correct data | ||
expected_data = json.dumps( | ||
{"emails": ["[email protected]", "[email protected]"], "topic": "Retro Topic"} | ||
{ | ||
"emails": ["[email protected]", "[email protected]"], | ||
"topic": "Retro Topic", | ||
"incident_document": "dummy_document_id", | ||
} | ||
) | ||
assert ( | ||
mock_client.views_open.call_args[1]["view"]["private_metadata"] == expected_data | ||
|
@@ -852,6 +865,15 @@ def test_schedule_incident_retro_successful_bots(): | |
"user": {"profile": {"email": "[email protected]", "bot_id": "B12345"}} | ||
}, # This simulates a bot user | ||
] | ||
mock_client.bookmarks_list.return_value = { | ||
"ok": True, | ||
"bookmarks": [ | ||
{ | ||
"title": "Incident report", | ||
"link": "https://docs.google.com/document/d/dummy_document_id/edit", | ||
} | ||
], | ||
} | ||
|
||
body = { | ||
"channel_id": "C1234567890", | ||
|
@@ -879,7 +901,11 @@ def test_schedule_incident_retro_successful_bots(): | |
|
||
# Verify the modal payload contains the correct data | ||
expected_data = json.dumps( | ||
{"emails": ["[email protected]", "[email protected]"], "topic": "Retro Topic"} | ||
{ | ||
"emails": ["[email protected]", "[email protected]"], | ||
"topic": "Retro Topic", | ||
"incident_document": "dummy_document_id", | ||
} | ||
) | ||
assert ( | ||
mock_client.views_open.call_args[1]["view"]["private_metadata"] == expected_data | ||
|
@@ -902,6 +928,15 @@ def test_schedule_incident_retro_successful_security_group(): | |
"user": {"profile": {"email": "[email protected]", "bot_id": "B12345"}} | ||
}, # This simulates a bot user | ||
] | ||
mock_client.bookmarks_list.return_value = { | ||
"ok": True, | ||
"bookmarks": [ | ||
{ | ||
"title": "Incident report", | ||
"link": "https://docs.google.com/document/d/dummy_document_id/edit", | ||
} | ||
], | ||
} | ||
|
||
body = { | ||
"channel_id": "C1234567890", | ||
|
@@ -929,7 +964,11 @@ def test_schedule_incident_retro_successful_security_group(): | |
|
||
# Verify the modal payload contains the correct data | ||
expected_data = json.dumps( | ||
{"emails": ["[email protected]"], "topic": "Retro Topic"} | ||
{ | ||
"emails": ["[email protected]"], | ||
"topic": "Retro Topic", | ||
"incident_document": "dummy_document_id", | ||
} | ||
) | ||
assert ( | ||
mock_client.views_open.call_args[1]["view"]["private_metadata"] == expected_data | ||
|
@@ -953,6 +992,15 @@ def test_schedule_incident_retro_successful_no_security_group(): | |
"user": {"profile": {"email": "[email protected]", "bot_id": "B12345"}} | ||
}, # This simulates a bot user | ||
] | ||
mock_client.bookmarks_list.return_value = { | ||
"ok": True, | ||
"bookmarks": [ | ||
{ | ||
"title": "Incident report", | ||
"link": "https://docs.google.com/document/d/dummy_document_id/edit", | ||
} | ||
], | ||
} | ||
|
||
body = { | ||
"channel_id": "C1234567890", | ||
|
@@ -980,7 +1028,11 @@ def test_schedule_incident_retro_successful_no_security_group(): | |
|
||
# Verify the modal payload contains the correct data | ||
expected_data = json.dumps( | ||
{"emails": ["[email protected]", "[email protected]"], "topic": "Retro Topic"} | ||
{ | ||
"emails": ["[email protected]", "[email protected]"], | ||
"topic": "Retro Topic", | ||
"incident_document": "dummy_document_id", | ||
} | ||
) | ||
assert ( | ||
mock_client.views_open.call_args[1]["view"]["private_metadata"] == expected_data | ||
|
@@ -995,6 +1047,15 @@ def test_schedule_incident_retro_with_no_users(): | |
"channel": {"topic": {"value": "Retro Topic"}} | ||
} | ||
mock_client.users_info.side_effect = [] | ||
mock_client.bookmarks_list.return_value = { | ||
"ok": True, | ||
"bookmarks": [ | ||
{ | ||
"title": "Incident report", | ||
"link": "https://docs.google.com/document/d/dummy_document_id/edit", | ||
} | ||
], | ||
} | ||
|
||
# Adjust the mock to simulate no users in the channel | ||
mock_client.conversations_members.return_value = {"members": []} | ||
|
@@ -1009,7 +1070,9 @@ def test_schedule_incident_retro_with_no_users(): | |
incident_helper.schedule_incident_retro(mock_client, body, mock_ack) | ||
|
||
# construct the expected data object | ||
expected_data = json.dumps({"emails": [], "topic": "Retro Topic"}) | ||
expected_data = json.dumps( | ||
{"emails": [], "topic": "Retro Topic", "incident_document": "dummy_document_id"} | ||
) | ||
# Assertions to validate behavior when no users are present in the channel | ||
assert ( | ||
mock_client.views_open.call_args[1]["view"]["private_metadata"] == expected_data | ||
|
@@ -1021,6 +1084,15 @@ def test_schedule_incident_retro_with_no_topic(): | |
mock_ack = MagicMock() | ||
mock_client.usergroups_users_list.return_value = {"users": ["U444444"]} | ||
mock_client.conversations_info.return_value = {"channel": {"topic": {"value": ""}}} | ||
mock_client.bookmarks_list.return_value = { | ||
"ok": True, | ||
"bookmarks": [ | ||
{ | ||
"title": "Incident report", | ||
"link": "https://docs.google.com/document/d/dummy_document_id/edit", | ||
} | ||
], | ||
} | ||
mock_client.users_info.side_effect = [] | ||
|
||
# Adjust the mock to simulate no users in the channel | ||
|
@@ -1036,7 +1108,13 @@ def test_schedule_incident_retro_with_no_topic(): | |
incident_helper.schedule_incident_retro(mock_client, body, mock_ack) | ||
|
||
# construct the expected data object and set the topic to a default one | ||
expected_data = json.dumps({"emails": [], "topic": "Incident Retro"}) | ||
expected_data = json.dumps( | ||
{ | ||
"emails": [], | ||
"topic": "Incident Retro", | ||
"incident_document": "dummy_document_id", | ||
} | ||
) | ||
# Assertions to validate behavior when no users are present in the channel | ||
assert ( | ||
mock_client.views_open.call_args[1]["view"]["private_metadata"] == expected_data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters