Skip to content

Commit

Permalink
test-backend: Raise zerver/views/report.py test coverage to 100%.
Browse files Browse the repository at this point in the history
  • Loading branch information
robot-dreams authored and timabbott committed Mar 1, 2017
1 parent 4968727 commit 7ed10da
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 0 additions & 1 deletion tools/test-backend
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ not_yet_fully_covered = {
# Getting views file coverage to 100% is a major project goal
'zerver/views/auth.py',
'zerver/views/messages.py',
'zerver/views/report.py',
'zerver/views/home.py',
'zerver/views/registration.py',
'zerver/views/events_register.py',
Expand Down
11 changes: 11 additions & 0 deletions zerver/tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,14 @@ def test_report_error(self):
with self.settings(BROWSER_ERROR_REPORTING=False):
result = self.client_post("/json/report_error", params)
self.assert_json_success(result)

# If js_source_map is present, then the stack trace should be annotated.
# DEBUG=False and TEST_SUITE=False are necessary to ensure that
# js_source_map actually gets instantiated.
with \
self.settings(DEBUG=False, TEST_SUITE=False), \
mock.patch('zerver.lib.unminify.SourceMap.annotate_stacktrace') as annotate:
result = self.client_post("/json/report_error", params)
self.assert_json_success(result)
# fix_params (see above) adds quotes when JSON encoding.
annotate.assert_called_once_with('"trace"')
14 changes: 10 additions & 4 deletions zerver/views/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
import subprocess
import os

# Read the source map information for decoding JavaScript backtraces
js_source_map = None
if not (settings.DEBUG or settings.TEST_SUITE):
js_source_map = SourceMap(os.path.join(
settings.DEPLOY_ROOT, 'prod-static/source-map'))

# Read the source map information for decoding JavaScript backtraces.
def get_js_source_map():
# type: () -> Optional[SourceMap]
global js_source_map
if not js_source_map and not (settings.DEBUG or settings.TEST_SUITE):
js_source_map = SourceMap(os.path.join(
settings.DEPLOY_ROOT, 'prod-static/source-map'))
return js_source_map

@authenticated_json_post_view
@has_request_variables
Expand Down Expand Up @@ -85,6 +90,7 @@ def json_report_error(request, user_profile, message=REQ(), stacktrace=REQ(),
if not settings.BROWSER_ERROR_REPORTING:
return json_success()

js_source_map = get_js_source_map()
if js_source_map:
stacktrace = js_source_map.annotate_stacktrace(stacktrace)

Expand Down

0 comments on commit 7ed10da

Please sign in to comment.