test_project_events.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. from django.urls import reverse
  2. from sentry.testutils.cases import APITestCase, SnubaTestCase
  3. from sentry.testutils.helpers.datetime import before_now, iso_format
  4. class ProjectEventsTest(APITestCase, SnubaTestCase):
  5. def test_simple(self):
  6. self.login_as(user=self.user)
  7. project = self.create_project()
  8. event_1 = self.store_event(
  9. data={"timestamp": iso_format(before_now(minutes=1))}, project_id=project.id
  10. )
  11. event_2 = self.store_event(
  12. data={"timestamp": iso_format(before_now(minutes=1))}, project_id=project.id
  13. )
  14. url = reverse(
  15. "sentry-api-0-project-events",
  16. kwargs={
  17. "organization_id_or_slug": project.organization.slug,
  18. "project_id_or_slug": project.slug,
  19. },
  20. )
  21. response = self.client.get(url, format="json")
  22. assert response.status_code == 200, response.content
  23. assert len(response.data) == 2
  24. assert sorted(map(lambda x: x["eventID"], response.data)) == sorted(
  25. [event_1.event_id, event_2.event_id]
  26. )
  27. def test_message_search(self):
  28. self.login_as(user=self.user)
  29. project = self.create_project()
  30. self.store_event(
  31. data={"message": "how to make fast", "timestamp": iso_format(before_now(minutes=1))},
  32. project_id=project.id,
  33. )
  34. event_2 = self.store_event(
  35. data={"message": "Delet the Data", "timestamp": iso_format(before_now(minutes=1))},
  36. project_id=project.id,
  37. )
  38. url = reverse(
  39. "sentry-api-0-project-events",
  40. kwargs={
  41. "organization_id_or_slug": project.organization.slug,
  42. "project_id_or_slug": project.slug,
  43. },
  44. )
  45. response = self.client.get(url, {"query": "delet"}, format="json")
  46. assert response.status_code == 200, response.content
  47. assert len(response.data) == 1
  48. assert response.data[0]["eventID"] == event_2.event_id
  49. assert response.data[0]["message"] == "Delet the Data"
  50. def test_filters_based_on_retention(self):
  51. self.login_as(user=self.user)
  52. project = self.create_project()
  53. self.store_event(data={"timestamp": iso_format(before_now(days=2))}, project_id=project.id)
  54. event_2 = self.store_event(
  55. data={"timestamp": iso_format(before_now(minutes=1))}, project_id=project.id
  56. )
  57. with self.options({"system.event-retention-days": 1}):
  58. url = reverse(
  59. "sentry-api-0-project-events",
  60. kwargs={
  61. "organization_id_or_slug": project.organization.slug,
  62. "project_id_or_slug": project.slug,
  63. },
  64. )
  65. response = self.client.get(url, format="json")
  66. assert response.status_code == 200, response.content
  67. assert len(response.data) == 1
  68. assert response.data[0]["eventID"] == event_2.event_id
  69. def test_limited_to_week(self):
  70. self.login_as(user=self.user)
  71. project = self.create_project()
  72. event = self.store_event(
  73. data={"timestamp": iso_format(before_now(days=2))}, project_id=project.id
  74. )
  75. self.store_event(data={"timestamp": iso_format(before_now(days=8))}, project_id=project.id)
  76. url = reverse(
  77. "sentry-api-0-project-events",
  78. kwargs={
  79. "organization_id_or_slug": project.organization.slug,
  80. "project_id_or_slug": project.slug,
  81. },
  82. )
  83. with self.feature("organizations:project-event-date-limit"):
  84. response = self.client.get(url, format="json")
  85. assert response.status_code == 200, response.content
  86. assert len(response.data) == 1
  87. assert response.data[0]["eventID"] == event.event_id
  88. def test_sample(self):
  89. self.login_as(user=self.user)
  90. project = self.create_project()
  91. event_1 = self.store_event(
  92. data={"timestamp": iso_format(before_now(minutes=1))}, project_id=project.id
  93. )
  94. event_2 = self.store_event(
  95. data={"timestamp": iso_format(before_now(minutes=1))}, project_id=project.id
  96. )
  97. url = reverse(
  98. "sentry-api-0-project-events",
  99. kwargs={
  100. "organization_id_or_slug": project.organization.slug,
  101. "project_id_or_slug": project.slug,
  102. },
  103. )
  104. response = self.client.get(url, {"sample": "true"}, format="json")
  105. assert response.status_code == 200, response.content
  106. assert len(response.data) == 2
  107. assert [event["eventID"] for event in response.data] == sorted(
  108. [event_1.event_id, event_2.event_id]
  109. )