mirror of https://github.com/zulip/zulip.git
tests: Test for PMs in test_export_realm_with_member_consent.
Sending PM from a hamlet(consented) to othello is a case of sending message from a consented user to a non consented user. This result in the generation of more than one message files during realm export. To handle this case _export_realm is updated.
This commit is contained in:
parent
21e7763886
commit
cc88f95229
|
@ -239,14 +239,21 @@ class ImportExportTest(ZulipTestCase):
|
|||
exportable_user_ids=exportable_user_ids,
|
||||
consent_message_id=consent_message_id,
|
||||
)
|
||||
# TODO: Process the second partial file, which can be created
|
||||
# for certain edge cases.
|
||||
export_usermessages_batch(
|
||||
input_path=os.path.join(output_dir, 'messages-000001.json.partial'),
|
||||
output_path=os.path.join(output_dir, 'messages-000001.json'),
|
||||
consent_message_id=consent_message_id,
|
||||
)
|
||||
|
||||
try:
|
||||
export_usermessages_batch(
|
||||
input_path=os.path.join(output_dir, 'messages-000002.json.partial'),
|
||||
output_path=os.path.join(output_dir, 'messages-000002.json'),
|
||||
consent_message_id=consent_message_id,
|
||||
)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
def read_file(fn: str) -> Any:
|
||||
full_fn = os.path.join(output_dir, fn)
|
||||
with open(full_fn) as f:
|
||||
|
@ -256,6 +263,12 @@ class ImportExportTest(ZulipTestCase):
|
|||
result['realm'] = read_file('realm.json')
|
||||
result['attachment'] = read_file('attachment.json')
|
||||
result['message'] = read_file('messages-000001.json')
|
||||
try:
|
||||
message = read_file('messages-000002.json')
|
||||
result["message"]["zerver_usermessage"].extend(message["zerver_usermessage"])
|
||||
result["message"]["zerver_message"].extend(message["zerver_message"])
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
result['uploads_dir'] = os.path.join(output_dir, 'uploads')
|
||||
result['uploads_dir_records'] = read_file(os.path.join('uploads', 'records.json'))
|
||||
result['emoji_dir'] = os.path.join(output_dir, 'emoji')
|
||||
|
@ -483,6 +496,12 @@ class ImportExportTest(ZulipTestCase):
|
|||
self.example_email("ZOE"),
|
||||
self.example_email("othello")])
|
||||
|
||||
# Create PMs
|
||||
pm_a_msg_id = self.send_personal_message(self.example_email("AARON"), self.example_email("othello"))
|
||||
pm_b_msg_id = self.send_personal_message(self.example_email("cordelia"), self.example_email("iago"))
|
||||
pm_c_msg_id = self.send_personal_message(self.example_email("hamlet"), self.example_email("othello"))
|
||||
pm_d_msg_id = self.send_personal_message(self.example_email("iago"), self.example_email("hamlet"))
|
||||
|
||||
# Send message advertising export and make users react
|
||||
self.send_stream_message(self.example_email("othello"), "Verona",
|
||||
topic_name="Export",
|
||||
|
@ -563,6 +582,11 @@ class ImportExportTest(ZulipTestCase):
|
|||
self.assertNotIn(stream_c_message_id, exported_msg_ids)
|
||||
self.assertNotIn(huddle_c_message_id, exported_msg_ids)
|
||||
|
||||
self.assertNotIn(pm_a_msg_id, exported_msg_ids)
|
||||
self.assertIn(pm_b_msg_id, exported_msg_ids)
|
||||
self.assertIn(pm_c_msg_id, exported_msg_ids)
|
||||
self.assertIn(pm_d_msg_id, exported_msg_ids)
|
||||
|
||||
def test_export_single_user(self) -> None:
|
||||
output_dir = self._make_output_dir()
|
||||
cordelia = self.example_user('cordelia')
|
||||
|
|
Loading…
Reference in New Issue