test_project_events.py 3.7 KB

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