oncall-engine/engine/apps/api/tests/conftest.py
Joey Orlando 5227ee3798
chore: random slack code cleanup (#5307)
# What this PR does

Related to https://github.com/grafana/oncall/pull/5287

Few random "clean-ups", type improvements, etc.

Additionally, fixes a change made in #5292; we should wait to read from
`slack_message.channel.slack_id`, until we've performed the
data-migration mentioned in that PR (in the mean-time we should continue
to use `slack_message._channel_id`).

## 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] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
2024-11-29 13:21:29 +00:00

57 lines
2.1 KiB
Python

import pytest
from django.utils import timezone
from apps.slack.client import SlackClient
@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(SlackClient, "api_call", _mock_api_call)
@pytest.fixture()
def make_resolved_ack_new_silenced_alert_groups(make_alert_group, 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() + timezone.timedelta(hours=1),
resolved_at=timezone.now() + timezone.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() + timezone.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() + timezone.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