test_example.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from __future__ import absolute_import
  2. import os
  3. import responses
  4. from sentry.utils import json
  5. from sentry.testutils import RelayStoreHelper, TransactionTestCase
  6. from sentry.testutils.helpers.datetime import iso_format, before_now
  7. def get_fixture_path(name):
  8. return os.path.join(os.path.dirname(__file__), "example-project", name)
  9. def load_fixture(name):
  10. with open(get_fixture_path(name)) as f:
  11. return f.read()
  12. class ExampleTestCase(RelayStoreHelper, TransactionTestCase):
  13. @responses.activate
  14. def test_sourcemap_expansion(self):
  15. responses.add(
  16. responses.GET,
  17. "http://example.com/test.js",
  18. body=load_fixture("test.js"),
  19. content_type="application/javascript",
  20. )
  21. responses.add(
  22. responses.GET,
  23. "http://example.com/test.min.js",
  24. body=load_fixture("test.min.js"),
  25. content_type="application/javascript",
  26. )
  27. responses.add(
  28. responses.GET,
  29. "http://example.com/test.map",
  30. body=load_fixture("test.map"),
  31. content_type="application/json",
  32. )
  33. responses.add(responses.GET, "http://example.com/index.html", body="Not Found", status=404)
  34. min_ago = iso_format(before_now(minutes=1))
  35. data = {
  36. "timestamp": min_ago,
  37. "message": "hello",
  38. "platform": "javascript",
  39. "exception": {
  40. "values": [
  41. {
  42. "type": "Error",
  43. "stacktrace": {
  44. "frames": json.loads(load_fixture("minifiedError.json"))[::-1]
  45. },
  46. }
  47. ]
  48. },
  49. }
  50. event = self.post_and_retrieve_event(data)
  51. exception = event.interfaces["exception"]
  52. frame_list = exception.values[0].stacktrace.frames
  53. assert len(frame_list) == 4
  54. assert frame_list[0].function == "produceStack"
  55. assert frame_list[0].lineno == 6
  56. assert frame_list[0].filename == "index.html"
  57. assert frame_list[1].function == "test"
  58. assert frame_list[1].lineno == 20
  59. assert frame_list[1].filename == "test.js"
  60. assert frame_list[2].function == "invoke"
  61. assert frame_list[2].lineno == 15
  62. assert frame_list[2].filename == "test.js"
  63. assert frame_list[3].function == "onFailure"
  64. assert frame_list[3].lineno == 5
  65. assert frame_list[3].filename == "test.js"