test_organization_alert_rules.py 2.3 KB

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