test_group_event_details.py 4.5 KB

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