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.
This commit is contained in:
Mohit Gupta 2020-07-19 20:28:15 +05:30 committed by Tim Abbott
parent 40d59f7cf4
commit c02e011be4
1 changed files with 5 additions and 1 deletions

View File

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