Skip to content

Commit

Permalink
added test for grouping alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaKerman committed Oct 20, 2024
1 parent cbe25dd commit dfac29f
Showing 1 changed file with 83 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from elementary.monitor.alerts.alerts_groups.alerts_group import AlertsGroup
from elementary.monitor.alerts.test_alert import TestAlertModel
from tests.mocks.data_monitoring.alerts.integrations.alerts_data_mock import (
AlertsDataMock,
)
Expand All @@ -8,6 +10,87 @@
)


@pytest.fixture
def base_integration_mock() -> BaseIntegrationMock:
return BaseIntegrationMock()


@pytest.fixture
def alerts_data_mock() -> AlertsDataMock:
return AlertsDataMock()


def test_group_alerts(base_integration_mock: BaseIntegrationMock):
assert (
base_integration_mock._group_alerts(alerts=[], threshold=1) == []
), "Empty list should return empty list"

alerts = [
TestAlertModel(
id="1",
test_unique_id="1",
elementary_unique_id="1",
test_name="1",
severity="WARN",
test_type="dbt_test",
test_sub_type="generic",
test_short_name="1",
alert_class_id="1",
)
]
grouped = base_integration_mock._group_alerts(alerts=alerts, threshold=2)
assert len(grouped) == 1, "Should return one group"
assert type(grouped[0]) is TestAlertModel, "Should be the same alert"
grouped = base_integration_mock._group_alerts(alerts=alerts, threshold=1)
assert len(grouped) == 1, "Should return one group"
assert type(grouped[0]) is AlertsGroup, "Group should contain alerts"

alerts = [
TestAlertModel(
id="1",
test_unique_id="1",
elementary_unique_id="1",
test_name="1",
severity="WARN",
test_type="dbt_test",
test_sub_type="generic",
test_short_name="1",
alert_class_id="1",
),
TestAlertModel(
id="2",
test_unique_id="2",
elementary_unique_id="2",
test_name="2",
severity="ERROR",
test_type="dbt_test",
test_sub_type="generic",
test_short_name="2",
alert_class_id="2",
),
TestAlertModel(
id="3",
test_unique_id="3",
elementary_unique_id="3",
test_name="3",
severity="ERROR",
test_type="dbt_test",
test_sub_type="generic",
test_short_name="3",
alert_class_id="3",
),
]
grouped = base_integration_mock._group_alerts(alerts=alerts, threshold=2)
assert len(grouped) == 1, "Should return one group"
assert type(grouped[0]) is AlertsGroup, "Group should contain alerts"
assert len(grouped[0].alerts) == 3, "Group should contain all alerts"
grouped = base_integration_mock._group_alerts(alerts=alerts, threshold=5)
assert len(grouped) == 3, "Should return three alerts"
assert type(grouped[0]) is TestAlertModel
assert type(grouped[1]) is TestAlertModel
assert type(grouped[2]) is TestAlertModel


def test_get_alert_template(
base_integration_mock: BaseIntegrationMock, alerts_data_mock: AlertsDataMock
):
Expand Down Expand Up @@ -41,13 +124,3 @@ def test_get_alert_template(
)
== "grouped_by_table"
)


@pytest.fixture
def base_integration_mock() -> BaseIntegrationMock:
return BaseIntegrationMock()


@pytest.fixture
def alerts_data_mock() -> AlertsDataMock:
return AlertsDataMock()

0 comments on commit dfac29f

Please sign in to comment.