test_organization_alert_rules.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. from django.utils import timezone
  2. from sentry.incidents.models import AlertRuleThresholdType, IncidentTrigger, TriggerStatus
  3. from sentry.models.rule import Rule
  4. from sentry.testutils.cases import AcceptanceTestCase, SnubaTestCase
  5. from sentry.testutils.silo import no_silo_test
  6. FEATURE_NAME = ["organizations:incidents"]
  7. @no_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. def test_alert_rules_list(self):
  18. Rule.objects.filter(project=self.project).update(date_added=timezone.now())
  19. self.create_alert_rule(
  20. name="My Alert Rule",
  21. date_added=timezone.now(),
  22. user=self.user,
  23. )
  24. with self.feature(FEATURE_NAME):
  25. self.browser.get(self.path)
  26. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  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"]')