test_decorators: Replace webhook logger mock with assertLogs.

Of the two other logging mocks left in this file, one checks
a logging call isn't made and another makes sure errors
aren't allowed by raising an exception as a side_effect
to the logger.
This commit is contained in:
Dinesh 2021-07-26 22:53:26 +05:30 committed by Tim Abbott
parent 199f522808
commit 2846d18854
1 changed files with 2 additions and 2 deletions

View File

@ -475,11 +475,11 @@ class DecoratorLoggingTestCase(ZulipTestCase):
request.body = b"{}" request.body = b"{}"
request.content_type = "text/plain" request.content_type = "text/plain"
with mock.patch("zerver.decorator.webhook_logger.exception") as mock_exception: with self.assertLogs("zulip.zerver.webhooks") as logger:
with self.assertRaisesRegex(Exception, "raised by webhook function"): with self.assertRaisesRegex(Exception, "raised by webhook function"):
my_webhook_raises_exception(request) my_webhook_raises_exception(request)
mock_exception.assert_called_with("raised by webhook function", stack_info=True) self.assertIn("raised by webhook function", logger.output[0])
def test_authenticated_rest_api_view_logging_unsupported_event(self) -> None: def test_authenticated_rest_api_view_logging_unsupported_event(self) -> None:
@authenticated_rest_api_view(webhook_client_name="ClientName") @authenticated_rest_api_view(webhook_client_name="ClientName")