test_project_events.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. from sentry.testutils.silo import region_silo_test
  5. @region_silo_test
  6. class ProjectEventsTest(APITestCase, SnubaTestCase):
  7. def test_simple(self):
  8. self.login_as(user=self.user)
  9. project = self.create_project()
  10. event_1 = self.store_event(
  11. data={"timestamp": iso_format(before_now(minutes=1))}, project_id=project.id
  12. )
  13. event_2 = self.store_event(
  14. data={"timestamp": iso_format(before_now(minutes=1))}, project_id=project.id
  15. )
  16. url = reverse(
  17. "sentry-api-0-project-events",
  18. kwargs={"organization_slug": project.organization.slug, "project_slug": project.slug},
  19. )
  20. response = self.client.get(url, format="json")
  21. assert response.status_code == 200, response.content
  22. assert len(response.data) == 2
  23. assert sorted(map(lambda x: x["eventID"], response.data)) == sorted(
  24. [event_1.event_id, event_2.event_id]
  25. )
  26. def test_message_search(self):
  27. self.login_as(user=self.user)
  28. project = self.create_project()
  29. self.store_event(
  30. data={"message": "how to make fast", "timestamp": iso_format(before_now(minutes=1))},
  31. project_id=project.id,
  32. )
  33. event_2 = self.store_event(
  34. data={"message": "Delet the Data", "timestamp": iso_format(before_now(minutes=1))},
  35. project_id=project.id,
  36. )
  37. url = reverse(
  38. "sentry-api-0-project-events",
  39. kwargs={"organization_slug": project.organization.slug, "project_slug": project.slug},
  40. )
  41. response = self.client.get(url, {"query": "delet"}, format="json")
  42. assert response.status_code == 200, response.content
  43. assert len(response.data) == 1
  44. assert response.data[0]["eventID"] == event_2.event_id
  45. assert response.data[0]["message"] == "Delet the Data"
  46. def test_filters_based_on_retention(self):
  47. self.login_as(user=self.user)
  48. project = self.create_project()
  49. self.store_event(data={"timestamp": iso_format(before_now(days=2))}, project_id=project.id)
  50. event_2 = self.store_event(
  51. data={"timestamp": iso_format(before_now(minutes=1))}, project_id=project.id
  52. )
  53. with self.options({"system.event-retention-days": 1}):
  54. url = reverse(
  55. "sentry-api-0-project-events",
  56. kwargs={
  57. "organization_slug": project.organization.slug,
  58. "project_slug": project.slug,
  59. },
  60. )
  61. response = self.client.get(url, format="json")
  62. assert response.status_code == 200, response.content
  63. assert len(response.data) == 1
  64. assert response.data[0]["eventID"] == event_2.event_id
  65. def test_limited_to_week(self):
  66. self.login_as(user=self.user)
  67. project = self.create_project()
  68. event = self.store_event(
  69. data={"timestamp": iso_format(before_now(days=2))}, project_id=project.id
  70. )
  71. self.store_event(data={"timestamp": iso_format(before_now(days=8))}, project_id=project.id)
  72. url = reverse(
  73. "sentry-api-0-project-events",
  74. kwargs={
  75. "organization_slug": project.organization.slug,
  76. "project_slug": project.slug,
  77. },
  78. )
  79. with self.feature("organizations:project-event-date-limit"):
  80. response = self.client.get(url, format="json")
  81. assert response.status_code == 200, response.content
  82. assert len(response.data) == 1
  83. assert response.data[0]["eventID"] == event.event_id