Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
mattermost_import: Add message with faulty HTML to fixture.
PieterCK5b32fa7227a5
diff --git a/zerver/tests/fixtures/mattermost_fixtures/export.json b/zerver/tests/fixtures/mattermost_fixtures/export.jsonindex d912d6b324e..47a9609593c 100644--- a/zerver/tests/fixtures/mattermost_fixtures/export.json+++ b/zerver/tests/fixtures/mattermost_fixtures/export.json@@ -12,6 +12,7 @@{"type":"user","user":{"username":"pansy","email":"[email protected]","auth_service":"","nickname":"","first_name":"","last_name":"","position":"","roles":"system_user","locale":"en","teams":[{"name":"slytherin","roles":"team_admin team_user","channels":[{"name":"slytherin-common-room","roles":"channel_admin channel_user","notify_props":{"desktop":"default","mobile":"default","mark_unread":"all"},"favorite":false},{"name":"slytherin-quidditch-team","roles":"channel_admin channel_user","notify_props":{"desktop":"default","mobile":"default","mark_unread":"all"},"favorite":false}]}],"notify_props":{"desktop":"mention","desktop_sound":"true","email":"true","mobile":"mention","mobile_push_status":"away","channel":"true","comments":"never","mention_keys":"malfoy,@malfoy"}}}{"type":"user","user":{"username":"snape","email":"[email protected]","auth_service":"","nickname":"","first_name":"Severus","last_name":"Snape","position":"","roles":"system_user","locale":"en","teams":[{"name":"slytherin","roles":"team_user","channels":[{"name":"slytherin-common-room","roles":"channel_user","notify_props":{"desktop":"default","mobile":"default","mark_unread":"all"},"favorite":false}]}],"notify_props":{"desktop":"mention","desktop_sound":"true","email":"true","mobile":"mention","mobile_push_status":"away","channel":"true","comments":"never","mention_keys":"snape,@snape"}}}{"type":"post","post":{"team":"gryffindor","channel":"dumbledores-army","user":"harry","message":"harry joined the channel.","create_at":1553166657086,"reactions":null,"replies":[{"user":"ron","message":"The weather is so hot!","create_at":1553166584976}]}}+{"type":"post","post":{"team":"gryffindor","channel":"dumbledores-army","user":"harry","message":"This will crash html2text!!! <g:brand><![CDATSALOMON NORTH AMERICA, IN}}]]></g:brand>","create_at":1553166657086,"reactions":null,"replies":[{"user":"ron","message":"The weather is so hot!","create_at":1553166584975}]}}{"type":"post","post":{"team":"gryffindor","channel":"gryffindor-common-room","user":"ron","message":"ron joined the channel.","create_at":1553166512493,"reactions":null,"replies":null}}{"type":"post","post":{"team":"gryffindor","channel":"gryffindor-quidditch-team","user":"harry","message":"harry joined the team.","create_at":1553165141670,"reactions":null,"replies":null}}{"type":"post","post":{"team":"gryffindor","channel":"gryffindor-quidditch-team","user":"harry","message":"Awesome!","create_at":1553166557928,"reactions":[{"user":"malfoy","create_at":1553166812156,"emoji_name":"tick"}],"replies":null}}diff --git a/zerver/tests/test_mattermost_importer.py b/zerver/tests/test_mattermost_importer.pyindex dc70a92a3a3..c4eeaafaf75 100644--- a/zerver/tests/test_mattermost_importer.py+++ b/zerver/tests/test_mattermost_importer.py@@ -1,6 +1,5 @@import filecmpimport os-import subprocessfrom typing import Anyfrom unittest.mock import call, patch@@ -53,7 +52,7 @@ class MatterMostImporter(ZulipTestCase):self.assertEqual(mattermost_data["user"][1]["username"], "harry")self.assert_length(mattermost_data["user"][1]["teams"], 1)- self.assert_length(mattermost_data["post"]["channel_post"], 20)+ self.assert_length(mattermost_data["post"]["channel_post"], 21)self.assertEqual(mattermost_data["post"]["channel_post"][0]["team"], "gryffindor")self.assertEqual(mattermost_data["post"]["channel_post"][0]["channel"], "dumbledores-army")self.assertEqual(mattermost_data["post"]["channel_post"][0]["user"], "harry")@@ -689,6 +688,9 @@ class MatterMostImporter(ZulipTestCase):warn_log.output,["WARNING:root:Skipping importing direct message groups and DMs since there are multiple teams in the export",+ # Check error log when trying to process a message with faulty HTML.+ "WARNING:root:Error converting HTML to text for message: 'This will crash html2text!!! <g:brand><![CDATSALOMON NORTH AMERICA, IN}}]]></g:brand>'; continuing",+ "WARNING:root:{'sender_id': 2, 'content': 'This will crash html2text!!! <g:brand><![CDATSALOMON NORTH AMERICA, IN}}]]></g:brand>', 'date_sent': 1553166657, 'reactions': [], 'channel_name': 'dumbledores-army'}","WARNING:root:Skipping importing direct message groups and DMs since there are multiple teams in the export",],)@@ -936,6 +938,8 @@ class MatterMostImporter(ZulipTestCase):warn_log.output,["WARNING:root:Skipping importing direct message groups and DMs since there are multiple teams in the export",+ "WARNING:root:Error converting HTML to text for message: 'Xxxx xxxx xxxxx xxxx2xxxx!!! <x:xxxxx><![XXXXXXXXXXX XXXXX XXXXXXX, XX}}]]></x:xxxxx>'; continuing",+ "WARNING:root:{'sender_id': 2, 'content': 'Xxxx xxxx xxxxx xxxx2xxxx!!! <x:xxxxx><![XXXXXXXXXXX XXXXX XXXXXXX, XX}}]]></x:xxxxx>', 'date_sent': 1553166657, 'reactions': [], 'channel_name': 'dumbledores-army'}","WARNING:root:Skipping importing direct message groups and DMs since there are multiple teams in the export",],)@@ -963,6 +967,8 @@ class MatterMostImporter(ZulipTestCase):warn_log.output,["WARNING:root:Skipping importing direct message groups and DMs since there are multiple teams in the export",+ "WARNING:root:Error converting HTML to text for message: 'Xxxx xxxx xxxxx xxxx2xxxx!!! <x:xxxxx><![XXXXXXXXXXX XXXXX XXXXXXX, XX}}]]></x:xxxxx>'; continuing",+ "WARNING:root:{'sender_id': 2, 'content': 'Xxxx xxxx xxxxx xxxx2xxxx!!! <x:xxxxx><![XXXXXXXXXXX XXXXX XXXXXXX, XX}}]]></x:xxxxx>', 'date_sent': 1553166657, 'reactions': [], 'channel_name': 'dumbledores-army'}","WARNING:root:Skipping importing direct message groups and DMs since there are multiple teams in the export",],)@@ -982,28 +988,3 @@ class MatterMostImporter(ZulipTestCase):self.assertIsNotNone(message.rendered_content)self.verify_emoji_code_foreign_keys()-- def test_fail_process_raw_message_batch(self) -> None:- # TODO: Once we have a sample of message content that can trigger this error- # we should add that as fixture instead of mocking `convert_html_to_text`.- mattermost_data_dir = self.fixture_file_name("", "mattermost_fixtures")- output_dir = self.make_import_output_dir("mattermost")-- with (- patch("builtins.print"),- patch("zerver.data_import.mattermost.convert_html_to_text") as mock_html2text,- self.assertLogs(level="WARNING") as warn_log,- ):- mock_html2text.side_effect = subprocess.CalledProcessError(- returncode=1, cmd="html2text", output="mocked failure"- )- do_convert_data(- mattermost_data_dir=mattermost_data_dir,- output_dir=output_dir,- masking_content=True,- )- mock_html2text.assert_called()- self.assertIn(- "WARNING:root:Error converting HTML to text for message: 'Xxxxxxx!'; continuing",- warn_log.output,- )