Skip to content

Commit

Permalink
add test to confirm no msg sent when workflow runs w/o error
Browse files Browse the repository at this point in the history
  • Loading branch information
nlebovits committed Oct 19, 2024
1 parent fe4e675 commit 949a528
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions data/src/test/test_slack_error_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ def test_send_error_to_slack(self, mock_getenv, mock_slack_post):
username="Backend Error Reporter",
)

@patch(
"classes.slack_error_reporter.WebClient.chat_postMessage"
) # Correct patching
@patch(
"classes.slack_error_reporter.os.getenv", return_value=None
) # Simulate missing Slack token
def test_no_error_no_slack_message(self, mock_getenv, mock_slack_post):
"""Test that Slack notification is not triggered if there's no error."""

# Call the Slack notification function (with no valid token)
with self.assertRaises(ValueError):
send_error_to_slack("Test error message")

# Ensure Slack's chat_postMessage was not called due to missing token
mock_slack_post.assert_not_called()


if __name__ == "__main__":
unittest.main()

0 comments on commit 949a528

Please sign in to comment.