test_group_event_details.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. from sentry.models.group import Group
  2. from sentry.testutils.cases import APITestCase, PerformanceIssueTestCase, SnubaTestCase
  3. from sentry.testutils.helpers.datetime import before_now, iso_format
  4. from sentry.testutils.silo import region_silo_test
  5. @region_silo_test
  6. class GroupEventDetailsTest(APITestCase, SnubaTestCase, PerformanceIssueTestCase):
  7. def setUp(self):
  8. super().setUp()
  9. self.login_as(user=self.user)
  10. project = self.create_project()
  11. min_ago = iso_format(before_now(minutes=1))
  12. two_min_ago = iso_format(before_now(minutes=2))
  13. self.event1 = self.store_event(
  14. data={
  15. "event_id": "a" * 32,
  16. "environment": "staging",
  17. "fingerprint": ["group_1"],
  18. "timestamp": two_min_ago,
  19. },
  20. project_id=project.id,
  21. )
  22. self.event2 = self.store_event(
  23. data={
  24. "event_id": "b" * 32,
  25. "environment": "production",
  26. "fingerprint": ["group_1"],
  27. "timestamp": min_ago,
  28. },
  29. project_id=project.id,
  30. )
  31. self.group = Group.objects.first()
  32. def test_snuba_no_environment_latest(self):
  33. url = f"/api/0/issues/{self.group.id}/events/latest/"
  34. response = self.client.get(url, format="json")
  35. assert response.status_code == 200
  36. assert response.data["id"] == str(self.event2.event_id)
  37. def test_snuba_no_environment_oldest(self):
  38. url = f"/api/0/issues/{self.group.id}/events/oldest/"
  39. response = self.client.get(url, format="json")
  40. assert response.status_code == 200
  41. assert response.data["id"] == str(self.event1.event_id)
  42. def test_snuba_no_environment_event_id(self):
  43. url = f"/api/0/issues/{self.group.id}/events/{self.event1.event_id}/"
  44. response = self.client.get(url, format="json")
  45. assert response.status_code == 200
  46. assert response.data["id"] == str(self.event1.event_id)
  47. def test_snuba_environment_latest(self):
  48. url = f"/api/0/issues/{self.group.id}/events/latest/"
  49. response = self.client.get(url, format="json", data={"environment": ["production"]})
  50. assert response.status_code == 200
  51. assert response.data["id"] == str(self.event2.event_id)
  52. def test_snuba_environment_oldest(self):
  53. url = f"/api/0/issues/{self.group.id}/events/oldest/"
  54. response = self.client.get(url, format="json", data={"environment": ["production"]})
  55. assert response.status_code == 200
  56. assert response.data["id"] == str(self.event2.event_id)
  57. def test_snuba_environment_event_id(self):
  58. url = f"/api/0/issues/{self.group.id}/events/{self.event2.event_id}/"
  59. response = self.client.get(url, format="json", data={"environment": ["production"]})
  60. assert response.status_code == 200
  61. assert response.data["id"] == str(self.event2.event_id)
  62. def test_simple_latest(self):
  63. url = f"/api/0/issues/{self.group.id}/events/latest/"
  64. response = self.client.get(url, format="json")
  65. assert response.status_code == 200
  66. assert response.data["eventID"] == str(self.event2.event_id)
  67. def test_simple_oldest(self):
  68. url = f"/api/0/issues/{self.group.id}/events/oldest/"
  69. response = self.client.get(url, format="json")
  70. assert response.status_code == 200
  71. assert response.data["id"] == str(self.event1.event_id)
  72. def test_simple_event_id(self):
  73. url = f"/api/0/issues/{self.group.id}/events/{self.event1.event_id}/"
  74. response = self.client.get(url, format="json")
  75. assert response.status_code == 200
  76. assert response.data["id"] == str(self.event1.event_id)
  77. def test_perf_issue_latest(self):
  78. event = self.create_performance_issue()
  79. url = f"/api/0/issues/{event.group.id}/events/latest/"
  80. response = self.client.get(url, format="json")
  81. assert response.status_code == 200
  82. assert response.data["eventID"] == event.event_id
  83. def test_perf_issue_oldest(self):
  84. event = self.create_performance_issue()
  85. url = f"/api/0/issues/{event.group.id}/events/oldest/"
  86. response = self.client.get(url, format="json")
  87. assert response.status_code == 200
  88. assert response.data["eventID"] == event.event_id
  89. def test_perf_issue_event_id(self):
  90. event = self.create_performance_issue()
  91. url = f"/api/0/issues/{event.group.id}/events/{event.event_id}/"
  92. response = self.client.get(url, format="json")
  93. assert response.status_code == 200
  94. assert response.data["eventID"] == event.event_id