test_group_events_latest.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from sentry.models import Group
  2. from sentry.testutils import APITestCase, SnubaTestCase
  3. from sentry.testutils.helpers.datetime import before_now, iso_format
  4. class GroupEventsLatestTest(APITestCase, SnubaTestCase):
  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(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_environment(self):
  36. url = f"/api/0/issues/{self.group.id}/events/latest/"
  37. response = self.client.get(url, format="json", data={"environment": ["production"]})
  38. assert response.status_code == 200
  39. assert response.data["id"] == str(self.event2.event_id)
  40. def test_simple(self):
  41. url = f"/api/0/issues/{self.group.id}/events/latest/"
  42. response = self.client.get(url, format="json")
  43. assert response.status_code == 200
  44. assert response.data["eventID"] == str(self.event2.event_id)