test_async_event_ingest.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from timeit import default_timer as timer
  2. from rest_framework.test import APITestCase
  3. from rest_framework import exceptions
  4. from rest_framework.test import APIRequestFactory
  5. from ..views import ABaseEventAPIView
  6. class AsyncEventStoreTestCase(APITestCase):
  7. def test_auth_from_request(self):
  8. factory = APIRequestFactory()
  9. dsn = "00000000000000000000000000000000"
  10. data = {"glitchtip_key": dsn}
  11. get_request = factory.post("/api/1/store/")
  12. get_request.GET = data
  13. data = [{"dsn": f"https://{dsn}@app.glitchtip.com/1"}]
  14. post_request = factory.post("/api/1/store/", data, format="json")
  15. post_request.data = data
  16. data = {"HTTP_X_SENTRY_AUTH": "sentry sentry_key=" + dsn}
  17. header_request = factory.post("/api/1/store/", headers=data)
  18. header_request.data = {}
  19. header_request.META = data
  20. invalid_request = factory.post("/api/1/store/", headers={})
  21. invalid_request.data = {}
  22. self.assertEqual(ABaseEventAPIView.auth_from_request(get_request), dsn)
  23. self.assertEqual(ABaseEventAPIView.auth_from_request(post_request), dsn)
  24. self.assertEqual(ABaseEventAPIView.auth_from_request(header_request), dsn)
  25. with self.assertRaises(exceptions.NotAuthenticated):
  26. ABaseEventAPIView.auth_from_request(invalid_request)
  27. if False:
  28. for request in [get_request, header_request, post_request]:
  29. start = timer()
  30. for _ in range(1):
  31. ABaseEventAPIView.auth_from_request(request)
  32. end = timer()
  33. print(end - start)