oncall-engine/engine/apps/alerts/tests/test_silence.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

54 lines
1.9 KiB
Python

import pytest
from django.utils import timezone
from apps.alerts.models import AlertReceiveChannel
@pytest.mark.django_db
def test_silence_alert_group(make_organization_and_user, make_alert_receive_channel, make_alert_group):
organization, _ = make_organization_and_user()
alert_receive_channel = make_alert_receive_channel(
organization, integration=AlertReceiveChannel.INTEGRATION_GRAFANA
)
alert_group = make_alert_group(alert_receive_channel)
alert_group.silence()
assert alert_group.silenced is True
assert alert_group.silenced_at is not None
@pytest.mark.django_db
def test_silence_by_user_alert_group(make_organization_and_user, make_alert_receive_channel, make_alert_group):
organization, _ = make_organization_and_user()
alert_receive_channel = make_alert_receive_channel(
organization, integration=AlertReceiveChannel.INTEGRATION_GRAFANA
)
alert_group = make_alert_group(alert_receive_channel)
alert_group.silence()
assert alert_group.silenced is True
assert alert_group.silenced_at is not None
@pytest.mark.django_db
def test_unsilence_alert_group(make_organization_and_user, make_alert_receive_channel, make_alert_group):
organization, user = make_organization_and_user()
alert_receive_channel = make_alert_receive_channel(
organization, integration=AlertReceiveChannel.INTEGRATION_GRAFANA
)
now = timezone.now()
silenced_until = now + timezone.timedelta(seconds=3600)
alert_group = make_alert_group(
alert_receive_channel,
silenced=True,
silenced_at=timezone.now(),
silenced_by_user=user,
silenced_until=silenced_until,
)
alert_group.un_silence()
assert alert_group.silenced is False
assert alert_group.silenced_at is None
assert alert_group.silenced_until is None
assert alert_group.silenced_by_user is None
assert alert_group.restarted_at is not None