test_javascript_processor.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import shutil
  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 ..models import Event
  7. sample_event = {
  8. "event_id": "cf536c31b68a473f97e579507ce155e3",
  9. "platform": "javascript",
  10. }
  11. sample_event = {
  12. "exception": {
  13. "values": [
  14. {
  15. "type": "Error",
  16. "value": "The error",
  17. "stacktrace": {
  18. "frames": [
  19. {
  20. "filename": "http://localhost:8080/dist/bundle.js",
  21. "function": "?",
  22. "in_app": True,
  23. "lineno": 2,
  24. "colno": 74016,
  25. },
  26. {
  27. "filename": "http://localhost:8080/dist/bundle.js",
  28. "function": "?",
  29. "in_app": True,
  30. "lineno": 2,
  31. "colno": 74012,
  32. },
  33. {
  34. "filename": "http://localhost:8080/dist/bundle.js",
  35. "function": "?",
  36. "in_app": True,
  37. "lineno": 2,
  38. "colno": 73992,
  39. },
  40. ]
  41. },
  42. "mechanism": {"type": "onerror", "handled": False},
  43. }
  44. ]
  45. },
  46. "level": "error",
  47. "platform": "javascript",
  48. "event_id": "0691751a89db419994efac8ac9b00a5d",
  49. "timestamp": 1648414309.82,
  50. "environment": "production",
  51. "request": {
  52. "url": "http://localhost:8080/",
  53. "headers": {
  54. "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:98.0) Gecko/20100101 Firefox/98.0"
  55. },
  56. },
  57. }
  58. class JavaScriptProcessorTestCase(APITestCase):
  59. def setUp(self):
  60. self.project = baker.make("projects.Project")
  61. self.organization = self.project.organization
  62. self.release = baker.make("releases.Release", organization=self.organization)
  63. self.release.projects.add(self.project)
  64. key = self.project.projectkey_set.first().public_key
  65. self.url = (
  66. reverse("event_store", args=[self.project.id]) + "?sentry_key=" + key.hex
  67. )
  68. def test_process_sourcemap(self):
  69. blob_bundle = baker.make("files.FileBlob", blob="uploads/file_blobs/bundle.js")
  70. blob_bundle_map = baker.make(
  71. "files.FileBlob", blob="uploads/file_blobs/bundle.js.map"
  72. )
  73. release_file_bundle = baker.make(
  74. "releases.ReleaseFile",
  75. release=self.release,
  76. file__name="bundle.js",
  77. file__blob=blob_bundle,
  78. )
  79. release_file_bundle_map = baker.make(
  80. "releases.ReleaseFile",
  81. release=self.release,
  82. file__name="bundle.js.map",
  83. file__blob=blob_bundle_map,
  84. )
  85. shutil.copyfile(
  86. "./events/tests/test_data/bundle.js", "./uploads/file_blobs/bundle.js"
  87. )
  88. shutil.copyfile(
  89. "./events/tests/test_data/bundle.js.map",
  90. "./uploads/file_blobs/bundle.js.map",
  91. )
  92. data = sample_event | {"release": self.release.version}
  93. res = self.client.post(self.url, data, format="json")
  94. self.assertTrue(Event.objects.filter(release=self.release).exists())