middleware: Pass unhandled API exceptions through to the test suite.

This results in more useful stack traces in failing tests.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-06-23 15:14:37 -07:00 committed by Tim Abbott
parent 2b35abba5d
commit 345ed1d09d
5 changed files with 6 additions and 23 deletions

View File

@ -1631,7 +1631,7 @@ class WebhookTestCase(ZulipTestCase):
complete_event_type is not None
and all_event_types is not None
and complete_event_type not in all_event_types
):
): # nocoverage
raise Exception(
f"""
Error: This test triggered a message using the event "{complete_event_type}", which was not properly

View File

@ -478,7 +478,7 @@ class JsonErrorHandler(MiddlewareMixin):
if isinstance(exception, JsonableError):
return json_response_from_error(exception)
if RequestNotes.get_notes(request).error_format == "JSON":
if RequestNotes.get_notes(request).error_format == "JSON" and not settings.TEST_SUITE:
capture_exception(exception)
json_error_logger = logging.getLogger("zerver.middleware.json_error_handler")
json_error_logger.error(traceback.format_exc(), extra=dict(request=request))

View File

@ -22,7 +22,7 @@ class TestIntegrationsDevPanel(ZulipTestCase):
"custom_headers": "{}",
"is_json": "true",
}
with self.assertLogs(level="ERROR") as logs:
with self.assertLogs(level="ERROR") as logs, self.settings(TEST_SUITE=False):
response = self.client_post(target_url, data)
self.assertEqual(response.status_code, 500) # Since the response would be forwarded.

View File

@ -81,7 +81,9 @@ class AdminNotifyHandlerTest(ZulipTestCase):
"django.request", level="ERROR"
) as request_error_log, self.assertLogs(
"zerver.middleware.json_error_handler", level="ERROR"
) as json_error_handler_log:
) as json_error_handler_log, self.settings(
TEST_SUITE=False
):
rate_limit_patch.side_effect = capture_and_throw
result = self.client_get("/json/users")
self.assert_json_error(result, "Internal server error", status_code=500)

View File

@ -114,25 +114,6 @@ Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6
expect_noop=True,
)
def test_travis_invalid_event(self) -> None:
payload = self.get_body("build")
payload = payload.replace("push", "invalid_event")
expected_error_messsage = """
Error: This test triggered a message using the event "invalid_event", which was not properly
registered via the @webhook_view(..., event_types=[...]). These registrations are important for Zulip
self-documenting the supported event types for this integration.
You can fix this by adding "invalid_event" to ALL_EVENT_TYPES for this webhook.
""".strip()
with self.assertLogs("django.request"):
with self.assertLogs("zerver.middleware.json_error_handler", level="ERROR") as m:
self.client_post(
self.url,
payload,
content_type="application/x-www-form-urlencoded",
)
self.assertIn(expected_error_messsage, m.output[0])
def test_travis_noop(self) -> None:
expected_error_message = """
While no message is expected given expect_noop=True,