test_serializers.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from model_bakery import baker
  2. from glitchtip.test_utils.test_case import GlitchTipTestCase
  3. from ..serializers import SpanSerializer, TransactionEventSerializer
  4. class TransactionEventSerializerTestCase(GlitchTipTestCase):
  5. def setUp(self):
  6. self.create_user_and_project()
  7. def test_serializer_tags(self):
  8. project = self.project
  9. project.release_id = None
  10. project.environment_id = None
  11. data = {
  12. "tags": {"http.status_code": "200"},
  13. "timestamp": "2020-12-29T17:51:08.468108Z",
  14. "start_timestamp": "2020-12-29T17:51:08.458023Z",
  15. "contexts": {
  16. "trace": {
  17. "trace_id": "581eb3bc1f4740eea53717cb7f7450f6",
  18. "op": "http.server",
  19. }
  20. },
  21. "transaction": "/",
  22. }
  23. serializer = TransactionEventSerializer(
  24. data=data, context={"request": {}, "project": project}
  25. )
  26. self.assertTrue(serializer.is_valid())
  27. transaction = serializer.save()
  28. data["tags"] = {"http.status_code": "400", "new": "foo"}
  29. serializer = TransactionEventSerializer(
  30. data=data, context={"request": {}, "project": project}
  31. )
  32. self.assertTrue(serializer.is_valid())
  33. transaction = serializer.save()
  34. self.assertEqual(len(transaction.group.tags["http.status_code"]), 2)
  35. self.assertEqual(len(transaction.group.tags["new"]), 1)
  36. class SpanSerializerTestCase(GlitchTipTestCase):
  37. def setUp(self):
  38. self.create_user_and_project()
  39. def test_description_is_optional(self):
  40. project = self.project
  41. project.release_id = None
  42. project.environment_id = None
  43. transaction = baker.make("performance.TransactionEvent", group__project=project)
  44. data = {
  45. "span_id": "d390335b84e74948",
  46. "trace_id": "581eb3bc1f4740eea53717cb7f7450f6",
  47. "start_timestamp": "2023-05-22T14:58:15.703399Z",
  48. "parent_span_id": "f9d24c19d5174f61",
  49. "timestamp": "2023-05-22T14:58:15.703515Z",
  50. "op": "sentry.sent",
  51. }
  52. serializer = SpanSerializer(
  53. data=data, context={"request": {}, "project": project}
  54. )
  55. self.assertTrue(serializer.is_valid())
  56. span = serializer.save(transaction=transaction)