test_envelope_api.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import json
  2. from django.shortcuts import reverse
  3. from rest_framework.test import APITestCase
  4. from model_bakery import baker
  5. from glitchtip import test_utils # pylint: disable=unused-import
  6. from performance.models import TransactionEvent
  7. from ..models import Event
  8. class EnvelopeStoreTestCase(APITestCase):
  9. def setUp(self):
  10. self.project = baker.make("projects.Project")
  11. self.projectkey = self.project.projectkey_set.first()
  12. self.params = f"?sentry_key={self.projectkey.public_key}"
  13. self.url = reverse("envelope_store", args=[self.project.id]) + self.params
  14. def get_payload(self, path):
  15. """ Convert JSON file into envelope format string """
  16. with open(path) as json_file:
  17. json_data = json.load(json_file)
  18. data = "\n".join([json.dumps(line) for line in json_data])
  19. return data
  20. def test_accept(self):
  21. data = self.get_payload("events/test_data/transactions/django_simple.json")
  22. res = self.client.generic("POST", self.url, data)
  23. self.assertEqual(res.status_code, 200)
  24. self.assertTrue(TransactionEvent.objects.exists())
  25. def test_android_sdk_event(self):
  26. data = self.get_payload(
  27. "events/test_data/incoming_events/android_sdk_envelope.json"
  28. )
  29. res = self.client.generic("POST", self.url, data)
  30. self.assertEqual(res.status_code, 200)
  31. self.assertTrue(Event.objects.exists())