test_organization_replay_events_meta.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import pytest
  2. from django.urls import reverse
  3. from sentry.testutils import APITestCase, SnubaTestCase
  4. from sentry.testutils.helpers.datetime import before_now, iso_format
  5. from sentry.testutils.silo import region_silo_test
  6. pytestmark = pytest.mark.sentry_metrics
  7. @region_silo_test
  8. class OrganizationEventsMetaEndpoint(APITestCase, SnubaTestCase):
  9. def setUp(self):
  10. super().setUp()
  11. self.min_ago = before_now(minutes=1)
  12. self.login_as(user=self.user)
  13. self.project_1 = self.create_project()
  14. self.project_2 = self.create_project()
  15. self.url = reverse(
  16. "sentry-api-0-organization-replay-events-meta",
  17. kwargs={"organization_slug": self.project.organization.slug},
  18. )
  19. self.features = {"organizations:session-replay": True}
  20. def test_simple(self):
  21. event_id_a = "a" * 32
  22. event_id_b = "b" * 32
  23. event_a = self.store_event(
  24. data={"event_id": event_id_a, "timestamp": iso_format(self.min_ago)},
  25. project_id=self.project_1.id,
  26. )
  27. event_b = self.store_event(
  28. data={"event_id": event_id_b, "timestamp": iso_format(self.min_ago)},
  29. project_id=self.project_2.id,
  30. )
  31. self.store_event(data={"timestamp": iso_format(self.min_ago)}, project_id=self.project_1.id)
  32. self.store_event(data={"timestamp": iso_format(self.min_ago)}, project_id=self.project_1.id)
  33. query = {"query": f"id:[{event_id_a}, {event_id_b}]"}
  34. with self.feature(self.features):
  35. response = self.client.get(self.url, query, format="json")
  36. expected = [
  37. {
  38. "error.type": [],
  39. "error.value": [],
  40. "id": event_id_a,
  41. "issue.id": 1,
  42. "issue": event_a.group.qualified_short_id,
  43. "project.name": self.project_1.slug,
  44. "timestamp": iso_format(self.min_ago) + "+00:00",
  45. "title": "<unlabeled event>",
  46. },
  47. {
  48. "error.type": [],
  49. "error.value": [],
  50. "id": event_id_b,
  51. "issue.id": 2,
  52. "issue": event_b.group.qualified_short_id,
  53. "project.name": self.project_2.slug,
  54. "timestamp": iso_format(self.min_ago) + "+00:00",
  55. "title": "<unlabeled event>",
  56. },
  57. ]
  58. assert response.status_code == 200, response.content
  59. assert response.data["data"] == expected