test_group.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from sentry.models import Group
  2. from sentry.testutils import SnubaTestCase, TestCase
  3. from sentry.testutils.helpers.datetime import before_now, iso_format
  4. class GroupTestSnuba(TestCase, SnubaTestCase):
  5. def test_get_oldest_latest_for_environments(self):
  6. project = self.create_project()
  7. min_ago = iso_format(before_now(minutes=1))
  8. self.store_event(
  9. data={
  10. "event_id": "a" * 32,
  11. "environment": "production",
  12. "timestamp": min_ago,
  13. "fingerprint": ["group-1"],
  14. },
  15. project_id=project.id,
  16. )
  17. self.store_event(
  18. data={
  19. "event_id": "b" * 32,
  20. "environment": "production",
  21. "timestamp": min_ago,
  22. "fingerprint": ["group-1"],
  23. },
  24. project_id=project.id,
  25. )
  26. self.store_event(
  27. data={"event_id": "c" * 32, "timestamp": min_ago, "fingerprint": ["group-1"]},
  28. project_id=project.id,
  29. )
  30. group = Group.objects.first()
  31. assert group.get_latest_event_for_environments().event_id == "c" * 32
  32. assert group.get_latest_event_for_environments(["staging"]) is None
  33. assert group.get_latest_event_for_environments(["production"]).event_id == "b" * 32
  34. assert group.get_oldest_event_for_environments().event_id == "a" * 32
  35. assert (
  36. group.get_oldest_event_for_environments(["staging", "production"]).event_id == "a" * 32
  37. )
  38. assert group.get_oldest_event_for_environments(["staging"]) is None