mirror of
https://github.com/zulip/zulip.git
synced 2025-10-28 18:43:52 +00:00
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:
committed by
Tim Abbott
parent
2b35abba5d
commit
345ed1d09d
@@ -1631,7 +1631,7 @@ class WebhookTestCase(ZulipTestCase):
|
|||||||
complete_event_type is not None
|
complete_event_type is not None
|
||||||
and all_event_types is not None
|
and all_event_types is not None
|
||||||
and complete_event_type not in all_event_types
|
and complete_event_type not in all_event_types
|
||||||
):
|
): # nocoverage
|
||||||
raise Exception(
|
raise Exception(
|
||||||
f"""
|
f"""
|
||||||
Error: This test triggered a message using the event "{complete_event_type}", which was not properly
|
Error: This test triggered a message using the event "{complete_event_type}", which was not properly
|
||||||
|
|||||||
@@ -478,7 +478,7 @@ class JsonErrorHandler(MiddlewareMixin):
|
|||||||
|
|
||||||
if isinstance(exception, JsonableError):
|
if isinstance(exception, JsonableError):
|
||||||
return json_response_from_error(exception)
|
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)
|
capture_exception(exception)
|
||||||
json_error_logger = logging.getLogger("zerver.middleware.json_error_handler")
|
json_error_logger = logging.getLogger("zerver.middleware.json_error_handler")
|
||||||
json_error_logger.error(traceback.format_exc(), extra=dict(request=request))
|
json_error_logger.error(traceback.format_exc(), extra=dict(request=request))
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class TestIntegrationsDevPanel(ZulipTestCase):
|
|||||||
"custom_headers": "{}",
|
"custom_headers": "{}",
|
||||||
"is_json": "true",
|
"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)
|
response = self.client_post(target_url, data)
|
||||||
|
|
||||||
self.assertEqual(response.status_code, 500) # Since the response would be forwarded.
|
self.assertEqual(response.status_code, 500) # Since the response would be forwarded.
|
||||||
|
|||||||
@@ -81,7 +81,9 @@ class AdminNotifyHandlerTest(ZulipTestCase):
|
|||||||
"django.request", level="ERROR"
|
"django.request", level="ERROR"
|
||||||
) as request_error_log, self.assertLogs(
|
) as request_error_log, self.assertLogs(
|
||||||
"zerver.middleware.json_error_handler", level="ERROR"
|
"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
|
rate_limit_patch.side_effect = capture_and_throw
|
||||||
result = self.client_get("/json/users")
|
result = self.client_get("/json/users")
|
||||||
self.assert_json_error(result, "Internal server error", status_code=500)
|
self.assert_json_error(result, "Internal server error", status_code=500)
|
||||||
|
|||||||
@@ -114,25 +114,6 @@ Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6
|
|||||||
expect_noop=True,
|
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:
|
def test_travis_noop(self) -> None:
|
||||||
expected_error_message = """
|
expected_error_message = """
|
||||||
While no message is expected given expect_noop=True,
|
While no message is expected given expect_noop=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user