From c02e011be4a67baa32f0312acee61da3ad657a54 Mon Sep 17 00:00:00 2001 From: Mohit Gupta Date: Sun, 19 Jul 2020 20:28:15 +0530 Subject: [PATCH] tests: Verify error logging of Internal Server Error in simulate_error. This commits verify error logs while simulate_error simulates an error using assertLogs so that the logs do not spam the test ouptut. --- zerver/tests/test_logging_handlers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/zerver/tests/test_logging_handlers.py b/zerver/tests/test_logging_handlers.py index 9a38509095..ac3db916dc 100644 --- a/zerver/tests/test_logging_handlers.py +++ b/zerver/tests/test_logging_handlers.py @@ -71,11 +71,15 @@ class AdminNotifyHandlerTest(ZulipTestCase): def simulate_error(self) -> logging.LogRecord: self.login('hamlet') - with patch("zerver.decorator.rate_limit") as rate_limit_patch: + with patch("zerver.decorator.rate_limit") as rate_limit_patch, \ + self.assertLogs('django.request', level='ERROR') as error_log: 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) rate_limit_patch.assert_called_once() + self.assertEqual(error_log.output, [ + 'ERROR:django.request:Internal Server Error: /json/users' + ]) record = self.logger.makeRecord( 'name',