test_organization_eventid.py 2.9 KB

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