test_organization_eventid.py 2.8 KB

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