test_organization_eventid.py 2.9 KB

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