test_incidents.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import pytz
  2. from django.utils import timezone
  3. from sentry.incidents.logic import update_incident_status
  4. from sentry.incidents.models import IncidentStatus, IncidentStatusMethod
  5. from sentry.testutils import AcceptanceTestCase, SnubaTestCase
  6. from sentry.testutils.helpers.datetime import before_now
  7. from sentry.testutils.silo import region_silo_test
  8. FEATURE_NAME = ["organizations:incidents", "organizations:performance-view"]
  9. event_time = before_now(days=3).replace(tzinfo=pytz.utc)
  10. @region_silo_test
  11. class OrganizationIncidentsListTest(AcceptanceTestCase, SnubaTestCase):
  12. def setUp(self):
  13. super().setUp()
  14. self.login_as(self.user)
  15. self.path = f"/organizations/{self.organization.slug}/alerts/"
  16. def test_empty_incidents(self):
  17. with self.feature(FEATURE_NAME):
  18. self.browser.get(self.path)
  19. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  20. self.browser.snapshot("incidents - empty state")
  21. def test_incidents_list(self):
  22. alert_rule = self.create_alert_rule(name="Alert Rule #1")
  23. incident = self.create_incident(
  24. self.organization,
  25. title="Incident #1",
  26. date_started=timezone.now(),
  27. date_detected=timezone.now(),
  28. projects=[self.project],
  29. alert_rule=alert_rule,
  30. )
  31. update_incident_status(
  32. incident, IncidentStatus.CRITICAL, status_method=IncidentStatusMethod.RULE_TRIGGERED
  33. )
  34. features = {feature: True for feature in FEATURE_NAME}
  35. with self.feature(features):
  36. self.browser.get(self.path)
  37. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  38. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  39. self.browser.snapshot("incidents - list")
  40. details_url = f'[href="/organizations/{self.organization.slug}/alerts/rules/details/{alert_rule.id}/?alert={incident.id}'
  41. self.browser.wait_until(details_url)
  42. self.browser.click(details_url)
  43. self.browser.wait_until_not('[data-test-id="loading-indicator"]')
  44. self.browser.wait_until_test_id("incident-rule-title")
  45. self.browser.wait_until_not('[data-test-id="loading-placeholder"]')
  46. self.browser.blur()
  47. self.browser.snapshot("incidents - details")