# What this PR does Extend list of exceptions to ignore on posting message to slack channel ## Which issue(s) this PR fixes https://github.com/grafana/oncall/issues/3694 ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required)
34 lines
1 KiB
Python
34 lines
1 KiB
Python
from unittest.mock import Mock, patch
|
|
|
|
import pytest
|
|
|
|
from apps.slack.client import SlackClient
|
|
from apps.slack.errors import (
|
|
SlackAPIChannelArchivedError,
|
|
SlackAPIChannelNotFoundError,
|
|
SlackAPIError,
|
|
SlackAPIInvalidAuthError,
|
|
SlackAPITokenError,
|
|
)
|
|
from apps.slack.utils import post_message_to_channel
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"error,raise_exception",
|
|
[
|
|
(SlackAPITokenError, False),
|
|
(SlackAPIChannelNotFoundError, False),
|
|
(SlackAPIChannelArchivedError, False),
|
|
(SlackAPIInvalidAuthError, False),
|
|
(SlackAPIError, True),
|
|
],
|
|
)
|
|
def test_post_message_to_channel(error, raise_exception):
|
|
organization = Mock()
|
|
with patch.object(SlackClient, "chat_postMessage", side_effect=error(Mock())) as mock_chat_postMessage:
|
|
if raise_exception:
|
|
with pytest.raises(SlackAPIError):
|
|
post_message_to_channel(organization, "test", "test")
|
|
else:
|
|
post_message_to_channel(organization, "test", "test")
|
|
mock_chat_postMessage.assert_called_once()
|