test_group_events_latest.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. from sentry.models import Group
  2. from sentry.testutils import APITestCase, SnubaTestCase
  3. from sentry.testutils.helpers.datetime import before_now, iso_format
  4. from sentry.testutils.silo import region_silo_test
  5. from sentry.types.issues import GroupType
  6. from sentry.utils.samples import load_data
  7. @region_silo_test
  8. class GroupEventsLatestTest(APITestCase, SnubaTestCase):
  9. endpoint = "sentry-api-0-events-latest"
  10. def setUp(self):
  11. super().setUp()
  12. self.login_as(user=self.user)
  13. project = self.create_project()
  14. min_ago = iso_format(before_now(minutes=1))
  15. two_min_ago = iso_format(before_now(minutes=2))
  16. self.event1 = self.store_event(
  17. data={
  18. "event_id": "a" * 32,
  19. "environment": "staging",
  20. "fingerprint": ["group_1"],
  21. "timestamp": two_min_ago,
  22. },
  23. project_id=project.id,
  24. )
  25. self.event2 = self.store_event(
  26. data={
  27. "event_id": "b" * 32,
  28. "environment": "production",
  29. "fingerprint": ["group_1"],
  30. "timestamp": min_ago,
  31. },
  32. project_id=project.id,
  33. )
  34. self.group = Group.objects.first()
  35. def test_snuba_no_environment(self):
  36. url = f"/api/0/issues/{self.group.id}/events/latest/"
  37. response = self.client.get(url, format="json")
  38. assert response.status_code == 200
  39. assert response.data["id"] == str(self.event2.event_id)
  40. def test_snuba_environment(self):
  41. url = f"/api/0/issues/{self.group.id}/events/latest/"
  42. response = self.client.get(url, format="json", data={"environment": ["production"]})
  43. assert response.status_code == 200
  44. assert response.data["id"] == str(self.event2.event_id)
  45. def test_simple(self):
  46. url = f"/api/0/issues/{self.group.id}/events/latest/"
  47. response = self.client.get(url, format="json")
  48. assert response.status_code == 200
  49. assert response.data["eventID"] == str(self.event2.event_id)
  50. def test_perf_issue(self):
  51. event_data = load_data(
  52. "transaction",
  53. fingerprint=[f"{GroupType.PERFORMANCE_N_PLUS_ONE_DB_QUERIES.value}-group1"],
  54. )
  55. event = self.store_event(data=event_data, project_id=self.project.id)
  56. url = f"/api/0/issues/{event.groups[0].id}/events/latest/"
  57. with self.feature("organizations:performance-issues"):
  58. response = self.client.get(url, format="json")
  59. assert response.status_code == 200
  60. assert response.data["eventID"] == event.event_id