test_group_events_oldest.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 GroupEventsOldestTest(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(self):
  34. url = f"/api/0/issues/{self.group.id}/events/oldest/"
  35. response = self.client.get(url, format="json")
  36. assert response.status_code == 200
  37. assert response.data["id"] == str(self.event1.event_id)
  38. def test_snuba_environment(self):
  39. url = f"/api/0/issues/{self.group.id}/events/oldest/"
  40. response = self.client.get(url, format="json", data={"environment": ["production"]})
  41. assert response.status_code == 200
  42. assert response.data["id"] == str(self.event2.event_id)
  43. def test_simple(self):
  44. url = f"/api/0/issues/{self.group.id}/events/oldest/"
  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_perf_issue(self):
  49. event = self.create_performance_issue()
  50. url = f"/api/0/issues/{event.group.id}/events/latest/"
  51. response = self.client.get(url, format="json")
  52. assert response.status_code == 200
  53. assert response.data["eventID"] == event.event_id