test_incidents.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from datetime import timezone
  2. from django.utils import timezone as django_timezone
  3. from sentry.incidents.logic import update_incident_status
  4. from sentry.incidents.models import IncidentStatus, IncidentStatusMethod
  5. from sentry.testutils.cases import AcceptanceTestCase, SnubaTestCase
  6. from sentry.testutils.helpers.datetime import before_now
  7. from sentry.testutils.silo import no_silo_test
  8. FEATURE_NAME = ["organizations:incidents", "organizations:performance-view"]
  9. event_time = before_now(days=3).replace(tzinfo=timezone.utc)
  10. @no_silo_test(stable=True)
  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=django_timezone.now(),
  27. date_detected=django_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")