# What this PR does - update `slackclient` dependency to latest version. The version we were using was 5 years old 😲 - first followed the v2 migration guide [here](https://github.com/slackapi/python-slack-sdk/wiki/Migrating-to-2.x) followed by the v3 migration guide [here](https://slack.dev/python-slack-sdk/v3-migration/). The main changes were: - The PyPI project was renamed from `slackclient` to `slack_sdk` - it is discouraged/harder to call `api_call` and encouraged to call the helper methods (ex. `chat_postMessage`; [note](https://github.com/slackapi/python-slack-sdk/wiki/Migrating-to-2.x#web-client-api-changes) in migration guide docs) - In 1.x, a failed api call would return the error payload to you and have you handle the error. In 2.x, a failed api call will throw an exception. To handle this in your code, you will have to wrap api calls with a try except block. Since we overload `WebClient.api_call` this was an easy change and only required a one line change - remove `apps.slack.slack_client.slack_server.SlackClientServer` class. The new version of `slack_sdk` handles the case that we needed to overload for in the first place. - merged `apps/slack/slack_client/slack_client.py` and `apps/slack/slack_client/exceptions.py` into `apps/slack/client.py` ## 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)
68 lines
2.5 KiB
Python
68 lines
2.5 KiB
Python
from datetime import timedelta
|
|
|
|
import pytest
|
|
from django.utils import timezone
|
|
|
|
from apps.slack.client import SlackClientWithErrorHandling
|
|
from apps.slack.scenarios.distribute_alerts import AlertShootingStep
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_slack_api_call(monkeypatch):
|
|
def _mock_api_call(*args, **kwargs):
|
|
return {
|
|
"status": 200,
|
|
"user": {
|
|
"profile": {"image_512": "TEST_SLACK_IMAGE_URL"},
|
|
"name": "TEST_SLACK_LOGIN",
|
|
"real_name": "TEST_SLACK_NAME",
|
|
},
|
|
"team": {"name": "TEST_SLACK_TEAM_NAME"},
|
|
}
|
|
|
|
monkeypatch.setattr(SlackClientWithErrorHandling, "api_call", _mock_api_call)
|
|
|
|
|
|
@pytest.fixture()
|
|
def make_resolved_ack_new_silenced_alert_groups(make_alert_group, make_alert_receive_channel, make_alert):
|
|
def _make_alert_groups_all_statuses(alert_receive_channel, channel_filter, alert_raw_request_data, **kwargs):
|
|
resolved_alert_group = make_alert_group(
|
|
alert_receive_channel,
|
|
channel_filter=channel_filter,
|
|
acknowledged_at=timezone.now() + timedelta(hours=1),
|
|
resolved_at=timezone.now() + timedelta(hours=2),
|
|
resolved=True,
|
|
acknowledged=True,
|
|
)
|
|
make_alert(alert_group=resolved_alert_group, raw_request_data=alert_raw_request_data)
|
|
|
|
ack_alert_group = make_alert_group(
|
|
alert_receive_channel,
|
|
channel_filter=channel_filter,
|
|
acknowledged_at=timezone.now() + timedelta(hours=1),
|
|
acknowledged=True,
|
|
)
|
|
make_alert(alert_group=ack_alert_group, raw_request_data=alert_raw_request_data)
|
|
|
|
new_alert_group = make_alert_group(alert_receive_channel, channel_filter=channel_filter)
|
|
make_alert(alert_group=new_alert_group, raw_request_data=alert_raw_request_data)
|
|
|
|
silenced_alert_group = make_alert_group(
|
|
alert_receive_channel,
|
|
channel_filter=channel_filter,
|
|
silenced=True,
|
|
silenced_at=timezone.now() + timedelta(hours=1),
|
|
)
|
|
make_alert(alert_group=silenced_alert_group, raw_request_data=alert_raw_request_data)
|
|
|
|
return resolved_alert_group, ack_alert_group, new_alert_group, silenced_alert_group
|
|
|
|
return _make_alert_groups_all_statuses
|
|
|
|
|
|
@pytest.fixture()
|
|
def mock_alert_shooting_step_post_alert_group_to_slack(monkeypatch):
|
|
def mock_post_alert_group_to_slack(*args, **kwargs):
|
|
return None
|
|
|
|
monkeypatch.setattr(AlertShootingStep, "_post_alert_group_to_slack", mock_post_alert_group_to_slack)
|