Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviamclaughlin authored Apr 25, 2024
1 parent d8a02d5 commit be0f1c4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 20 deletions.
6 changes: 4 additions & 2 deletions app/integrations/google_workspace/google_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ def insert_event(start, end, emails, title, incident_document, **kwargs):
else:
# Optionally handle the case where 'incident_document' is None or empty
# For example, remove 'attachments' from 'body' if it shouldn't exist without a valid document
body.pop("attachments", None) # This removes 'attachments' if it exists, does nothing if it doesn't

body.pop(
"attachments", None
) # This removes 'attachments' if it exists, does nothing if it doesn't

body.update({convert_string_to_camel_case(k): v for k, v in kwargs.items()})
if "delegated_user_email" in kwargs and kwargs["delegated_user_email"] is not None:
delegated_user_email = kwargs["delegated_user_email"]
Expand Down
36 changes: 24 additions & 12 deletions app/tests/integrations/google_workspace/test_google_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ def test_insert_event_no_kwargs_no_delegated_email(
"summary": title,
"guestsCanModify": True,
"attachments": [
{
"fileUrl": f"https://docs.google.com/document/d/{document_id}",
"mimeType": "application/vnd.google-apps.document",
"title": "Incident Document",
}
{
"fileUrl": f"https://docs.google.com/document/d/{document_id}",
"mimeType": "application/vnd.google-apps.document",
"title": "Incident Document",
}
],
},
calendarId="primary",
supportsAttachments=True
supportsAttachments=True,
)
assert not mock_convert_string_to_camel_case.called
assert mock_os_environ_get.called_once_with("SRE_BOT_EMAIL")
Expand All @@ -205,9 +205,17 @@ def test_insert_event_with_kwargs(
"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"}]
"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)
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",
Expand All @@ -225,13 +233,14 @@ def test_insert_event_with_kwargs(
**kwargs,
},
calendarId="primary",
supportsAttachments=True
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")
Expand All @@ -246,14 +255,16 @@ def test_insert_event_with_no_document(
end = start
emails = ["[email protected]", "[email protected]"]
title = "Test Event"
document_id = ""
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, document_id, **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",
Expand All @@ -271,13 +282,14 @@ def test_insert_event_with_no_document(
**kwargs,
},
calendarId="primary",
supportsAttachments=True
supportsAttachments=True,
)
for key in kwargs:
mock_convert_string_to_camel_case.assert_any_call(key)

assert not mock_os_environ_get.called


@patch("integrations.google_workspace.google_service.handle_google_api_errors")
@patch("os.environ.get", return_value="test_email")
@patch("integrations.google_workspace.google_calendar.execute_google_api_call")
Expand Down
36 changes: 30 additions & 6 deletions app/tests/modules/incident/test_incident_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,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", "incident_document": "dummy_document_id"}
{
"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
Expand Down Expand Up @@ -897,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", "incident_document": "dummy_document_id"}
{
"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
Expand Down Expand Up @@ -956,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", "incident_document": "dummy_document_id"}
{
"emails": ["[email protected]"],
"topic": "Retro Topic",
"incident_document": "dummy_document_id",
}
)
assert (
mock_client.views_open.call_args[1]["view"]["private_metadata"] == expected_data
Expand Down Expand Up @@ -1016,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", "incident_document": "dummy_document_id"}
{
"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
Expand Down Expand Up @@ -1054,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", "incident_document": "dummy_document_id"})
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
Expand Down Expand Up @@ -1090,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", "incident_document": "dummy_document_id"})
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
Expand Down

0 comments on commit be0f1c4

Please sign in to comment.