test_group_events_latest.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 GroupEventsLatestTest(APITestCase, SnubaTestCase, PerformanceIssueTestCase):
  8. endpoint = "sentry-api-0-events-latest"
  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/latest/"
  36. response = self.client.get(url, format="json")
  37. assert response.status_code == 200
  38. assert response.data["id"] == str(self.event2.event_id)
  39. def test_snuba_environment(self):
  40. url = f"/api/0/issues/{self.group.id}/events/latest/"
  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/latest/"
  46. response = self.client.get(url, format="json")
  47. assert response.status_code == 200
  48. assert response.data["eventID"] == str(self.event2.event_id)
  49. def test_perf_issue(self):
  50. event = self.create_performance_issue()
  51. url = f"/api/0/issues/{event.group.id}/events/latest/"
  52. response = self.client.get(url, format="json")
  53. assert response.status_code == 200
  54. assert response.data["eventID"] == event.event_id