From a2d948f2e041c59c1857d0e16b62076deae15878 Mon Sep 17 00:00:00 2001 From: Susan Salituro Date: Sat, 18 Mar 2017 12:10:37 -0700 Subject: [PATCH] test_messages: Add test for invalid markdown format. --- zerver/tests/test_messages.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/zerver/tests/test_messages.py b/zerver/tests/test_messages.py index 5c14c600ce..e9f0d7f1ef 100644 --- a/zerver/tests/test_messages.py +++ b/zerver/tests/test_messages.py @@ -629,6 +629,34 @@ class MessageDictTest(ZulipTestCase): self.assertEqual(message.rendered_content, expected_content) self.assertEqual(message.rendered_content_version, bugdown.version) + @mock.patch("zerver.lib.message.bugdown.convert") + def test_applying_markdown_invalid_format(self, convert_mock): + # type: (Any) -> None + # pretend the converter returned an invalid message without raising an exception + convert_mock.return_value = None + sender = get_user_profile_by_email('othello@zulip.com') + receiver = get_user_profile_by_email('hamlet@zulip.com') + recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL) + sending_client = make_client(name="test suite") + message = Message( + sender=sender, + recipient=recipient, + subject='whatever', + content='hello **world**', + pub_date=timezone.now(), + sending_client=sending_client, + last_edit_time=timezone.now(), + edit_history='[]' + ) + message.save() + + # An important part of this test is to get the message through this exact code path, + # because there is an ugly hack we need to cover. So don't just say "row = message". + row = Message.get_raw_db_rows([message.id])[0] + dct = MessageDict.build_dict_from_raw_db_row(row, apply_markdown=True) + error_content = '

[Zulip note: Sorry, we could not understand the formatting of your message]

' + self.assertEqual(dct['content'], error_content) + def test_reaction(self): # type: () -> None sender = get_user_profile_by_email('othello@zulip.com')