test_organization_eventid.py 2.8 KB

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