test-backend: Raise zerver/views/report.py test coverage to 100%.

This commit is contained in:
Elliott Jin 2017-02-28 19:19:56 -08:00 committed by Tim Abbott
parent 49687272a9
commit 7ed10da4ad
3 changed files with 21 additions and 5 deletions

View File

@ -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',

View File

@ -143,3 +143,14 @@ class TestReport(ZulipTestCase):
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"')

View File

@ -18,11 +18,16 @@ from typing import Optional, Text
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
@ -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)