tests: Verify error logs while data export for zulip.

This commit verify that error logging while testing data export in
test_notify_realm_export_on_failure using assertLogs so that the logs
do not spam test output.
This commit is contained in:
Mohit Gupta
2020-07-19 19:39:17 +05:30
committed by Tim Abbott
parent ef5ad080e2
commit 40d59f7cf4

View File

@@ -2418,12 +2418,18 @@ class NormalActionsTest(BaseAction):
self.login_user(self.user_profile)
with mock.patch('zerver.lib.export.do_export_realm',
side_effect=Exception("test")):
side_effect=Exception("test")), \
self.assertLogs(level="ERROR") as error_log:
with stdout_suppressed():
events = self.verify_action(
lambda: self.client_post('/json/export/realm'),
state_change_expected=False, num_events=2)
# Log is of following format: "ERROR:root:Data export for zulip failed after 0.004499673843383789"
# Where last floating number is time and will vary in each test hence the following assertion is
# independent of time bit by not matching exact log but only part of it.
self.assertTrue("ERROR:root:Data export for zulip failed after" in error_log.output[0])
pending_schema_checker('events[0]', events[0])
failed_schema_checker('events[1]', events[1])