Skip to content

Commit c920e26

Browse files
committed
stop hardcoding type
1 parent e74950d commit c920e26

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/sentry/monitors/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ def update_issue_alert_rule(
392392

393393

394394
def ensure_cron_detector(monitor: Monitor):
395+
from sentry.issues.grouptype import MonitorCheckInFailure
396+
395397
try:
396398
with atomic_transaction(using=router.db_for_write(DataSource)):
397399
data_source, created = DataSource.objects.get_or_create(
@@ -401,7 +403,7 @@ def ensure_cron_detector(monitor: Monitor):
401403
)
402404
if created:
403405
detector = Detector.objects.create(
404-
type="monitor_check_in_failure",
406+
type=MonitorCheckInFailure.slug,
405407
project_id=monitor.project_id,
406408
name=monitor.name,
407409
owner_user_id=monitor.owner_user_id,

tests/sentry/monitors/test_utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from django.db import IntegrityError
44

5+
from sentry.issues.grouptype import MonitorIncidentType
56
from sentry.monitors.types import DATA_SOURCE_CRON_MONITOR
67
from sentry.monitors.utils import ensure_cron_detector
78
from sentry.testutils.cases import TestCase
@@ -28,7 +29,7 @@ def test_creates_data_source_and_detector_for_new_monitor(self):
2829
)
2930
assert data_source is not None
3031
detector = Detector.objects.get(
31-
type="monitor_check_in_failure",
32+
type=MonitorIncidentType.slug,
3233
project_id=self.monitor.project_id,
3334
name=self.monitor.name,
3435
)
@@ -48,7 +49,7 @@ def test_idempotent_for_existing_data_source(self):
4849
source_id=str(self.monitor.id),
4950
)
5051
detector = Detector.objects.get(
51-
type="monitor_check_in_failure",
52+
type=MonitorIncidentType.slug,
5253
project_id=self.monitor.project_id,
5354
name=self.monitor.name,
5455
)
@@ -63,7 +64,7 @@ def test_idempotent_for_existing_data_source(self):
6364
source_id=str(self.monitor.id),
6465
)
6566
detector_after = Detector.objects.get(
66-
type="monitor_check_in_failure",
67+
type=MonitorIncidentType.slug,
6768
project_id=self.monitor.project_id,
6869
name=self.monitor.name,
6970
)
@@ -80,7 +81,7 @@ def test_with_owner_user(self):
8081
self.monitor.save()
8182
ensure_cron_detector(self.monitor)
8283
detector = Detector.objects.get(
83-
type="monitor_check_in_failure",
84+
type=MonitorIncidentType.slug,
8485
project_id=self.monitor.project_id,
8586
)
8687
assert detector.owner_user_id == self.user.id
@@ -90,7 +91,7 @@ def test_with_no_owner(self):
9091
ensure_cron_detector(self.monitor)
9192

9293
detector = Detector.objects.get(
93-
type="monitor_check_in_failure",
94+
type=MonitorIncidentType.slug,
9495
project_id=self.monitor.project_id,
9596
)
9697
assert detector.owner_user_id is None

0 commit comments

Comments
 (0)