Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tests: Default ENABLE_FILE_LINKS to False.
Alex Vandiver08191d3f69ca
diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.pyindex 34534199ee4..8d5309c2bb4 100644--- a/zerver/lib/markdown/__init__.py+++ b/zerver/lib/markdown/__init__.py@@ -245,7 +245,7 @@ def get_web_link_regex() -> Pattern[str]:return verbose_compile(REGEX)-def clear_state_for_testing() -> None:+def clear_web_link_regex_for_testing() -> None:# The link regex never changes in production, but our tests# try out both sides of ENABLE_FILE_LINKS, so we need# a way to clear it.diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.pyindex 9e32efb21bc..4ef6ae6c52a 100644--- a/zerver/tests/test_markdown.py+++ b/zerver/tests/test_markdown.py@@ -33,7 +33,7 @@ from zerver.lib.markdown import (InlineInterestingLinkProcessor,MarkdownListPreprocessor,MessageRenderingResult,- clear_state_for_testing,+ clear_web_link_regex_for_testing,content_has_emoji_syntax,fetch_tweet_data,get_tweet_id,@@ -464,11 +464,6 @@ Outside. Should convert:<>class MarkdownTest(ZulipTestCase):- @override- def setUp(self) -> None:- super().setUp()- clear_state_for_testing()-@overridedef assertEqual(self, first: Any, second: Any, msg: str = "") -> None:if isinstance(first, str) and isinstance(second, str):@@ -573,20 +568,27 @@ class MarkdownTest(ZulipTestCase):def test_inline_file(self) -> None:msg = "Check out this file file:///Volumes/myserver/Users/Shared/pi.py"- converted = markdown_convert_wrapper(msg)++ # Make separate realms because the markdown engines cache the+ # linkifiers on them, including if ENABLE_FILE_LINKS was used+ realm = do_create_realm(string_id="file_links_disabled", name="File links disabled")self.assertEqual(- converted,- '<p>Check out this file <a href="file:///Volumes/myserver/Users/Shared/pi.py">file:///Volumes/myserver/Users/Shared/pi.py</a></p>',+ markdown_convert(msg, message_realm=realm).rendered_content,+ "<p>Check out this file file:///Volumes/myserver/Users/Shared/pi.py</p>",)+ clear_web_link_regex_for_testing()+++ try:+ with self.settings(ENABLE_FILE_LINKS=True):+ realm = do_create_realm(string_id="file_links_enabled", name="File links enabled")+ self.assertEqual(+ markdown_convert(msg, message_realm=realm).rendered_content,+ '<p>Check out this file <a href="file:///Volumes/myserver/Users/Shared/pi.py">file:///Volumes/myserver/Users/Shared/pi.py</a></p>',+ )+ finally:+ clear_web_link_regex_for_testing()- clear_state_for_testing()- with self.settings(ENABLE_FILE_LINKS=False):- realm = do_create_realm(string_id="file_links_test", name="file_links_test")- maybe_update_markdown_engines(realm.id, False)- self.assertEqual(- markdown_convert(msg, message_realm=realm).rendered_content,- "<p>Check out this file file:///Volumes/myserver/Users/Shared/pi.py</p>",- )def test_inline_bitcoin(self) -> None:msg = "To bitcoin:1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa or not to bitcoin"diff --git a/zproject/test_extra_settings.py b/zproject/test_extra_settings.pyindex af455a38659..37f604c86cc 100644--- a/zproject/test_extra_settings.py+++ b/zproject/test_extra_settings.py@@ -131,9 +131,6 @@ if not PUPPETEER_TESTS:set_loglevel("zerver.worker", "WARNING")set_loglevel("stripe", "WARNING")-# Enable file:/// hyperlink support by default in tests-ENABLE_FILE_LINKS = True-# This is set dynamically in `zerver/lib/test_runner.py`.# Allow setting LOCAL_UPLOADS_DIR in the environment so that the# frontend/API tests in test_server.py can control this.