test_group_event_details.py 4.6 KB

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