test_events: Fix realm export test to actually work.

The previous iteration still had the failure mode of not actually
testing anything, because it didn't trigger the data export code path
(and in fact was getting an HTTP 401 authentication denied error).
This commit is contained in:
Tim Abbott 2019-08-07 12:49:54 -07:00
parent 22842dab34
commit 4e631876f4
1 changed files with 11 additions and 13 deletions

View File

@ -94,7 +94,6 @@ from zerver.lib.actions import (
get_typing_user_profiles,
log_event,
lookup_default_stream_groups,
notify_realm_export,
notify_realm_custom_profile_fields,
check_add_user_group,
do_update_user_group_name,
@ -2760,11 +2759,6 @@ class EventsRegisterTest(ZulipTestCase):
self.assert_on_error(error)
def test_notify_realm_export(self) -> None:
# Create the `realm_exported` RealmAuditLog object
with mock.patch('zerver.lib.export.do_export_realm',
return_value=create_dummy_file('test-export.tar.gz')):
self.client_post('/json/export/realm')
schema_checker = self.check_events_dict([
('type', equals('realm_export')),
('exports', check_list(check_dict_only([
@ -2778,13 +2772,17 @@ class EventsRegisterTest(ZulipTestCase):
])))
])
# Traditionally, we'd be testing the endpoint, but that
# requires somewhat annoying mocking setup for what to do with
# the export tarball.
events = self.do_test(
lambda: notify_realm_export(self.user_profile),
state_change_expected=False, num_events=1)
error = schema_checker('events[0]', events[0])
do_change_is_admin(self.user_profile, True)
self.login(self.user_profile.email)
with mock.patch('zerver.lib.export.do_export_realm',
return_value=create_dummy_file('test-export.tar.gz')):
events = self.do_test(
lambda: print(self.client_post('/json/export/realm').content),
state_change_expected=True, num_events=2)
# The first event is a message from notification-bot.
error = schema_checker('events[1]', events[1])
self.assert_on_error(error)
class FetchInitialStateDataTest(ZulipTestCase):