test_organization_eventid.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from django.urls import NoReverseMatch, reverse
  2. from freezegun import freeze_time
  3. from sentry.testutils import APITestCase, SnubaTestCase
  4. from sentry.testutils.helpers.datetime import before_now, iso_format
  5. class EventIdLookupEndpointTest(APITestCase, SnubaTestCase):
  6. def setUp(self):
  7. super().setUp()
  8. min_ago = iso_format(before_now(minutes=1))
  9. self.org = self.create_organization(owner=self.user)
  10. self.project = self.create_project(organization=self.org)
  11. self.event = self.store_event(
  12. data={
  13. "event_id": "b" * 32,
  14. "message": "oh no",
  15. "timestamp": min_ago,
  16. "fingerprint": ["group-1"],
  17. },
  18. project_id=self.project.id,
  19. )
  20. self.group = self.event.group
  21. self.login_as(user=self.user)
  22. def test_simple(self):
  23. url = reverse(
  24. "sentry-api-0-event-id-lookup",
  25. kwargs={"organization_slug": self.org.slug, "event_id": self.event.event_id},
  26. )
  27. response = self.client.get(url, format="json")
  28. assert response.status_code == 200, response.content
  29. assert response.data["organizationSlug"] == self.org.slug
  30. assert response.data["projectSlug"] == self.project.slug
  31. assert response.data["groupId"] == str(self.group.id)
  32. assert response.data["eventId"] == str(self.event.event_id)
  33. assert response.data["event"]["id"] == str(self.event.event_id)
  34. def test_missing_eventid(self):
  35. url = reverse(
  36. "sentry-api-0-event-id-lookup",
  37. kwargs={"organization_slug": self.org.slug, "event_id": "c" * 32},
  38. )
  39. response = self.client.get(url, format="json")
  40. assert response.status_code == 404, response.content
  41. def test_ratelimit(self):
  42. url = reverse(
  43. "sentry-api-0-event-id-lookup",
  44. kwargs={"organization_slug": self.org.slug, "event_id": self.event.event_id},
  45. )
  46. with freeze_time("2000-01-01"):
  47. for i in range(10):
  48. self.client.get(url, format="json")
  49. resp = self.client.get(url, format="json")
  50. assert resp.status_code == 429
  51. def test_invalid_event_id(self):
  52. with self.assertRaises(NoReverseMatch):
  53. reverse(
  54. "sentry-api-0-event-id-lookup",
  55. kwargs={
  56. "organization_slug": self.org.slug,
  57. "event_id": "not-an-event",
  58. },
  59. )
  60. url = reverse(
  61. "sentry-api-0-event-id-lookup",
  62. kwargs={"organization_slug": self.org.slug, "event_id": 123456},
  63. )
  64. resp = self.client.get(url, format="json")
  65. assert resp.status_code == 400