diff --git a/zerver/lib/markdown/__init__.py b/zerver/lib/markdown/__init__.py index 34534199ee..8d5309c2bb 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.py index 9e32efb21b..4ef6ae6c52 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() - @override def 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) - self.assertEqual( - converted, - '

Check out this file file:///Volumes/myserver/Users/Shared/pi.py

', - ) - 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, - "

Check out this file file:///Volumes/myserver/Users/Shared/pi.py

", - ) + # 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( + markdown_convert(msg, message_realm=realm).rendered_content, + "

Check out this file file:///Volumes/myserver/Users/Shared/pi.py

", + ) + 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, + '

Check out this file file:///Volumes/myserver/Users/Shared/pi.py

', + ) + finally: + clear_web_link_regex_for_testing() + 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.py index af455a3865..37f604c86c 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.