test_javascript_processor.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. release_file_bundle = baker.make(
  70. "releases.ReleaseFile", release=self.release, file__name="bundle.js"
  71. )
  72. release_file_bundle_map = baker.make(
  73. "releases.ReleaseFile", release=self.release, file__name="bundle.js.map"
  74. )
  75. blob_bundle = baker.make("files.FileBlob", blob="uploads/file_blobs/bundle.js")
  76. blob_bundle_map = baker.make(
  77. "files.FileBlob", blob="uploads/file_blobs/bundle.js.map"
  78. )
  79. release_file_bundle.file.blobs.add(blob_bundle)
  80. release_file_bundle_map.file.blobs.add(blob_bundle_map)
  81. shutil.copyfile(
  82. "./events/tests/test_data/bundle.js", "./uploads/file_blobs/bundle.js"
  83. )
  84. shutil.copyfile(
  85. "./events/tests/test_data/bundle.js.map",
  86. "./uploads/file_blobs/bundle.js.map",
  87. )
  88. data = sample_event | {"release": self.release.version}
  89. res = self.client.post(self.url, data, format="json")
  90. self.assertTrue(Event.objects.filter(release=self.release).exists())