Skip to content

Commit

Permalink
BUG: fix when no email_address found
Browse files Browse the repository at this point in the history
currently we assume every user-query generates an email_address which is not None - handle case when it is None
  • Loading branch information
anish-mudaraddi committed Dec 4, 2023
1 parent 15c26b2 commit 77ba93c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/workflows/email/send_decom_flavor_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def find_user_info(user_id, cloud_account, override_email_address):
res = user_query.to_props(flatten=True)
if not res:
return "", override_email_address
if not res["user_email"][0]:
return "", override_email_address
return res["user_name"][0], res["user_email"][0]


Expand Down
29 changes: 29 additions & 0 deletions tests/lib/workflows/email/test_send_decom_flavor_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,35 @@ def test_find_user_info_invalid(mock_user_query):
assert res[1] == mock_override_email


@patch("workflows.email.send_decom_flavor_email.UserQuery")
def test_find_user_info_no_email_address(mock_user_query):
"""
Tests find_user_info where query result contains no email address
"""
mock_user_id = NonCallableMock()
mock_cloud_account = NonCallableMock()
mock_override_email = NonCallableMock()
mock_user_query.return_value.to_props.return_value = {
"user_id": ["foo"],
"user_email": [None],
}
res = find_user_info(mock_user_id, mock_cloud_account, mock_override_email)
mock_user_query.assert_called_once()
mock_user_query.return_value.select.assert_called_once_with(
UserProperties.USER_NAME, UserProperties.USER_EMAIL
)
mock_user_query.return_value.where.assert_called_once_with(
QueryPresetsGeneric.EQUAL_TO, UserProperties.USER_ID, value=mock_user_id
)
mock_user_query.return_value.run.assert_called_once_with(
cloud_account=mock_cloud_account
)
mock_user_query.return_value.to_props.assert_called_once_with(flatten=True)

assert res[0] == ""
assert res[1] == mock_override_email


@patch("workflows.email.send_decom_flavor_email.FlavorQuery")
def test_find_users_with_decom_flavor_valid(mock_flavor_query):
"""
Expand Down

0 comments on commit 77ba93c

Please sign in to comment.