test_serializers.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from glitchtip.test_utils.test_case import GlitchTipTestCase
  2. from ..serializers import TransactionEventSerializer
  3. class TransactionEventSerializerTestCase(GlitchTipTestCase):
  4. def setUp(self):
  5. self.create_user_and_project()
  6. def test_serializer_tags(self):
  7. project = self.project
  8. project.release_id = None
  9. project.environment_id = None
  10. data = {
  11. "tags": {"http.status_code": "200"},
  12. "timestamp": "2020-12-29T17:51:08.468108Z",
  13. "start_timestamp": "2020-12-29T17:51:08.458023Z",
  14. "contexts": {
  15. "trace": {
  16. "trace_id": "581eb3bc1f4740eea53717cb7f7450f6",
  17. "op": "http.server",
  18. }
  19. },
  20. "transaction": "/",
  21. }
  22. serializer = TransactionEventSerializer(
  23. data=data, context={"request": {}, "project": project}
  24. )
  25. self.assertTrue(serializer.is_valid())
  26. transaction = serializer.save()
  27. data["tags"] = {"http.status_code": "400", "new": "foo"}
  28. serializer = TransactionEventSerializer(
  29. data=data, context={"request": {}, "project": project}
  30. )
  31. self.assertTrue(serializer.is_valid())
  32. transaction = serializer.save()
  33. self.assertEqual(len(transaction.group.tags["http.status_code"]), 2)
  34. self.assertEqual(len(transaction.group.tags["new"]), 1)