test_example.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import os
  2. import responses
  3. from sentry.testutils import RelayStoreHelper, TransactionTestCase
  4. from sentry.testutils.helpers.datetime import before_now, iso_format
  5. def get_fixture_path(name):
  6. return os.path.join(os.path.dirname(__file__), "fixtures", name)
  7. def load_fixture(name):
  8. with open(get_fixture_path(name)) as f:
  9. return f.read()
  10. class ExampleTestCase(RelayStoreHelper, TransactionTestCase):
  11. @responses.activate
  12. def test_sourcemap_expansion(self):
  13. responses.add(
  14. responses.GET,
  15. "http://example.com/test.js",
  16. body=load_fixture("example/test.js"),
  17. content_type="application/javascript",
  18. )
  19. responses.add(
  20. responses.GET,
  21. "http://example.com/test.min.js",
  22. body=load_fixture("example/test.min.js"),
  23. content_type="application/javascript",
  24. )
  25. responses.add(
  26. responses.GET,
  27. "http://example.com/test.min.js.map",
  28. body=load_fixture("example/test.min.js.map"),
  29. content_type="application/json",
  30. )
  31. responses.add(responses.GET, "http://example.com/index.html", body="Not Found", status=404)
  32. min_ago = iso_format(before_now(minutes=1))
  33. data = {
  34. "timestamp": min_ago,
  35. "message": "hello",
  36. "platform": "javascript",
  37. "exception": {
  38. "values": [
  39. {
  40. "type": "Error",
  41. "stacktrace": {
  42. "frames": [
  43. {
  44. "abs_path": "http://example.com/index.html",
  45. "filename": "index.html",
  46. "lineno": 6,
  47. "colno": 7,
  48. "function": "produceStack",
  49. },
  50. {
  51. "abs_path": "http://example.com/test.min.js",
  52. "filename": "test.min.js",
  53. "lineno": 1,
  54. "colno": 183,
  55. "function": "i",
  56. },
  57. {
  58. "abs_path": "http://example.com/test.min.js",
  59. "filename": "test.min.js",
  60. "lineno": 1,
  61. "colno": 136,
  62. "function": "r",
  63. },
  64. {
  65. "abs_path": "http://example.com/test.min.js",
  66. "filename": "test.min.js",
  67. "lineno": 1,
  68. "colno": 64,
  69. "function": "e",
  70. },
  71. ]
  72. },
  73. }
  74. ]
  75. },
  76. }
  77. event = self.post_and_retrieve_event(data)
  78. exception = event.interfaces["exception"]
  79. frame_list = exception.values[0].stacktrace.frames
  80. assert len(frame_list) == 4
  81. assert frame_list[0].function == "produceStack"
  82. assert frame_list[0].lineno == 6
  83. assert frame_list[0].filename == "index.html"
  84. assert frame_list[1].function == "test"
  85. assert frame_list[1].lineno == 20
  86. assert frame_list[1].filename == "test.js"
  87. assert frame_list[2].function == "invoke"
  88. assert frame_list[2].lineno == 15
  89. assert frame_list[2].filename == "test.js"
  90. assert frame_list[3].function == "onFailure"
  91. assert frame_list[3].lineno == 5
  92. assert frame_list[3].filename == "test.js"