test_organization_alert_rules.py 2.4 KB

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