Skip to content

Commit

Permalink
add tests for channel filter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwheeler-ep committed Jan 6, 2025
1 parent 792a402 commit 039bb4e
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 1 deletion.
97 changes: 96 additions & 1 deletion engine/apps/alerts/tests/test_channel_filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from apps.alerts.models import ChannelFilter
from apps.alerts.models import ChannelFilter, Alert


@pytest.mark.django_db
Expand Down Expand Up @@ -216,3 +216,98 @@ def test_slack_channel_or_org_default_none(

# Assert that slack_channel_or_org_default returns None
assert channel_filter.slack_channel_or_org_default is None
@pytest.mark.django_db
def test_channel_filter_team_update(
make_organization_and_user_with_plugin_token,
make_team,
make_escalation_chain,
make_alert_receive_channel,
make_channel_filter,
):
organization, user, token = make_organization_and_user_with_plugin_token()
team = make_team(organization)

alert_receive_channel = make_alert_receive_channel(organization)

escalation_chain = make_escalation_chain(organization=organization)
escalation_chain.team = team

channel_filter = make_channel_filter(alert_receive_channel, escalation_chain=escalation_chain, is_default=True)

channel_filter.update_team = True

alert_group = Alert.create(
title="the title",
message="the message",
alert_receive_channel=alert_receive_channel,
raw_request_data={},
integration_unique_data={},
image_url=None,
link_to_upstream_details=None,
channel_filter=channel_filter
).group

assert list(alert_group.teams.all()) == [team]

@pytest.mark.django_db
def test_channel_filter_no_team_set(
make_organization_and_user_with_plugin_token,
make_team,
make_escalation_chain,
make_alert_receive_channel,
make_channel_filter,
):
organization, user, token = make_organization_and_user_with_plugin_token()
team = make_team(organization)

alert_receive_channel = make_alert_receive_channel(organization, team=team)

escalation_chain = make_escalation_chain(organization=organization)

channel_filter = make_channel_filter(alert_receive_channel, escalation_chain=escalation_chain, is_default=True)

alert_group = Alert.create(
title="the title",
message="the message",
alert_receive_channel=alert_receive_channel,
raw_request_data={},
integration_unique_data={},
image_url=None,
link_to_upstream_details=None
).group

assert list(alert_group.teams.all()) == [team]

@pytest.mark.django_db
def test_channel_filter_no_escalation_chain(
make_organization_and_user_with_plugin_token,
make_team,
make_escalation_chain,
make_alert_receive_channel,
make_channel_filter,
):
organization, user, token = make_organization_and_user_with_plugin_token()
team = make_team(organization)

alert_receive_channel = make_alert_receive_channel(organization)

escalation_chain = make_escalation_chain(organization=organization)
escalation_chain.team = team

make_channel_filter(alert_receive_channel, escalation_chain=escalation_chain, is_default=True)
channel_filter = make_channel_filter(alert_receive_channel, is_default=True)

channel_filter.update_team = True

alert_group = Alert.create(
title="the title",
message="the message",
alert_receive_channel=alert_receive_channel,
raw_request_data={},
integration_unique_data={},
image_url=None,
link_to_upstream_details=None,
channel_filter=channel_filter
).group

assert list(alert_group.teams.all()) == []
42 changes: 42 additions & 0 deletions engine/apps/api/tests/test_alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2435,3 +2435,45 @@ def test_filter_default_started_at(
)
assert response.status_code == status.HTTP_200_OK
assert response.json()["pk"] == old_alert_group.public_primary_key



@pytest.mark.django_db
def test_update_team(
make_organization_and_user_with_plugin_token,
make_alert_receive_channel,
make_alert_group,
make_alert,
make_user_auth_headers,
make_escalation_chain,
make_team,
make_channel_filter
):
organization, user, token = make_organization_and_user_with_plugin_token()

team = make_team(organization)

alert_receive_channel = make_alert_receive_channel(organization)

escalation_chain = make_escalation_chain(organization=organization, team=team)

channel_filter = make_channel_filter(alert_receive_channel, escalation_chain=escalation_chain, is_default=True, update_team=True)


alert_group = Alert.create(
title="the title",
message="the message",
alert_receive_channel=alert_receive_channel,
raw_request_data={},
integration_unique_data={},
image_url=None,
link_to_upstream_details=None
).group

client = APIClient()
url = reverse("api-internal:alertgroup-detail", kwargs={"pk": alert_group.public_primary_key})

response = client.get(url, **make_user_auth_headers(user, token))

assert response.status_code == status.HTTP_200_OK
assert response.json()['teams'][0]["id"] == team.public_primary_key

0 comments on commit 039bb4e

Please sign in to comment.