test_incidents.py 2.3 KB

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