test_organization_alert_rules.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from django.utils import timezone
  2. from sentry.incidents.models import AlertRuleThresholdType, IncidentTrigger, TriggerStatus
  3. from sentry.models import Rule
  4. from sentry.testutils import AcceptanceTestCase, SnubaTestCase
  5. from sentry.testutils.silo import region_silo_test
  6. FEATURE_NAME = ["organizations:incidents"]
  7. @region_silo_test
  8. class OrganizationAlertRulesListTest(AcceptanceTestCase, SnubaTestCase):
  9. def setUp(self):
  10. super().setUp()
  11. self.login_as(self.user)
  12. self.path = f"/organizations/{self.organization.slug}/alerts/rules/"
  13. def test_empty_alert_rules(self):
  14. with self.feature(FEATURE_NAME):
  15. self.browser.get(self.path)
  16. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  17. self.browser.snapshot("alert rules - empty state")
  18. def test_alert_rules_list(self):
  19. Rule.objects.filter(project=self.project).update(date_added=timezone.now())
  20. self.create_alert_rule(
  21. name="My Alert Rule",
  22. date_added=timezone.now(),
  23. user=self.user,
  24. )
  25. with self.feature(FEATURE_NAME):
  26. self.browser.get(self.path)
  27. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  28. self.browser.snapshot("alert rules - list")
  29. def test_alert_rules_alert_list(self):
  30. self.create_alert_rule(
  31. name="My Alert Rule",
  32. projects=[self.project],
  33. date_added=timezone.now(),
  34. user=self.user,
  35. )
  36. alert_rule_critical = self.create_alert_rule(
  37. organization=self.organization,
  38. projects=[self.project],
  39. name="some rule [crit]",
  40. query="",
  41. aggregate="count()",
  42. time_window=1,
  43. threshold_type=AlertRuleThresholdType.ABOVE,
  44. resolve_threshold=10,
  45. threshold_period=1,
  46. )
  47. trigger = self.create_alert_rule_trigger(
  48. alert_rule=alert_rule_critical, alert_threshold=100
  49. )
  50. crit_incident = self.create_incident(status=20, alert_rule=alert_rule_critical)
  51. IncidentTrigger.objects.create(
  52. incident=crit_incident, alert_rule_trigger=trigger, status=TriggerStatus.ACTIVE.value
  53. )
  54. with self.feature(["organizations:incidents"]):
  55. self.browser.get(self.path)
  56. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  57. self.browser.snapshot("alert rules - alert list")