test_group_events_oldest.py 2.5 KB

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