tests: Default ENABLE_FILE_LINKS to False.

Test configuration should mirror default production as much as possible.
This commit is contained in:
Alex Vandiver 2024-07-18 14:28:16 +00:00 committed by Tim Abbott
parent e02e9c9181
commit 08191d3f69
3 changed files with 22 additions and 23 deletions

View File

@ -245,7 +245,7 @@ def get_web_link_regex() -> Pattern[str]:
return verbose_compile(REGEX) 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 # The link regex never changes in production, but our tests
# try out both sides of ENABLE_FILE_LINKS, so we need # try out both sides of ENABLE_FILE_LINKS, so we need
# a way to clear it. # a way to clear it.

View File

@ -33,7 +33,7 @@ from zerver.lib.markdown import (
InlineInterestingLinkProcessor, InlineInterestingLinkProcessor,
MarkdownListPreprocessor, MarkdownListPreprocessor,
MessageRenderingResult, MessageRenderingResult,
clear_state_for_testing, clear_web_link_regex_for_testing,
content_has_emoji_syntax, content_has_emoji_syntax,
fetch_tweet_data, fetch_tweet_data,
get_tweet_id, get_tweet_id,
@ -464,11 +464,6 @@ Outside. Should convert:<>
class MarkdownTest(ZulipTestCase): class MarkdownTest(ZulipTestCase):
@override
def setUp(self) -> None:
super().setUp()
clear_state_for_testing()
@override @override
def assertEqual(self, first: Any, second: Any, msg: str = "") -> None: def assertEqual(self, first: Any, second: Any, msg: str = "") -> None:
if isinstance(first, str) and isinstance(second, str): if isinstance(first, str) and isinstance(second, str):
@ -573,20 +568,27 @@ class MarkdownTest(ZulipTestCase):
def test_inline_file(self) -> None: def test_inline_file(self) -> None:
msg = "Check out this file file:///Volumes/myserver/Users/Shared/pi.py" msg = "Check out this file file:///Volumes/myserver/Users/Shared/pi.py"
converted = markdown_convert_wrapper(msg)
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>',
)
clear_state_for_testing() # Make separate realms because the markdown engines cache the
with self.settings(ENABLE_FILE_LINKS=False): # linkifiers on them, including if ENABLE_FILE_LINKS was used
realm = do_create_realm(string_id="file_links_test", name="file_links_test") realm = do_create_realm(string_id="file_links_disabled", name="File links disabled")
maybe_update_markdown_engines(realm.id, False) self.assertEqual(
self.assertEqual( markdown_convert(msg, message_realm=realm).rendered_content,
markdown_convert(msg, message_realm=realm).rendered_content, "<p>Check out this file file:///Volumes/myserver/Users/Shared/pi.py</p>",
"<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()
def test_inline_bitcoin(self) -> None: def test_inline_bitcoin(self) -> None:
msg = "To bitcoin:1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa or not to bitcoin" msg = "To bitcoin:1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa or not to bitcoin"

View File

@ -131,9 +131,6 @@ if not PUPPETEER_TESTS:
set_loglevel("zerver.worker", "WARNING") set_loglevel("zerver.worker", "WARNING")
set_loglevel("stripe", "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`. # This is set dynamically in `zerver/lib/test_runner.py`.
# Allow setting LOCAL_UPLOADS_DIR in the environment so that the # Allow setting LOCAL_UPLOADS_DIR in the environment so that the
# frontend/API tests in test_server.py can control this. # frontend/API tests in test_server.py can control this.