From 806d8f2dc7dcafd5fb85403bf4c3729fda0fb72e Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Sat, 1 Jul 2023 13:02:52 +0530 Subject: [PATCH] test_markdown: Merge similar tests into a single test case. This prep commit merges separate tests for '**@all**', '**@stream**' and '**@everyone**' stream wildcard mentions into a single test named 'test_mention_stream_wildcard'. Similarly, it merges separate tests for '@all', '@stream', and '@everyone' stream wildcard mentions into a single test named 'test_mention_at_stream_wildcard'. The aim is to finally have two separate tests for stream and topic wildcard mentions (when we introduce topic wildcards) instead of having separate tests for each mention text (i.e. all, everyone, stream, topic). --- zerver/tests/test_markdown.py | 64 +++++++++-------------------------- 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/zerver/tests/test_markdown.py b/zerver/tests/test_markdown.py index 5316cca3ba..e61fde60a1 100644 --- a/zerver/tests/test_markdown.py +++ b/zerver/tests/test_markdown.py @@ -1826,61 +1826,29 @@ class MarkdownTest(ZulipTestCase): with_language, without_language = re.findall(r"
(.*?)$", rendered, re.MULTILINE)
         self.assertFalse(with_language == without_language)
 
-    def test_mention_wildcard(self) -> None:
+    def test_mention_stream_wildcard(self) -> None:
         user_profile = self.example_user("othello")
         msg = Message(sender=user_profile, sending_client=get_client("test"))
 
-        content = "@**all** test"
-        rendering_result = render_markdown(msg, content)
-        self.assertEqual(
-            rendering_result.rendered_content,
-            '

@all test

', - ) - self.assertTrue(rendering_result.mentions_stream_wildcard) + for stream_wildcard in stream_wildcards: + content = f"@**{stream_wildcard}** test" + rendering_result = render_markdown(msg, content) + self.assertEqual( + rendering_result.rendered_content, + f'

@{stream_wildcard} test

', + ) + self.assertTrue(rendering_result.mentions_stream_wildcard) - def test_mention_everyone(self) -> None: + def test_mention_at_stream_wildcard(self) -> None: user_profile = self.example_user("othello") msg = Message(sender=user_profile, sending_client=get_client("test")) - content = "@**everyone** test" - rendering_result = render_markdown(msg, content) - self.assertEqual( - rendering_result.rendered_content, - '

@everyone test

', - ) - self.assertTrue(rendering_result.mentions_stream_wildcard) - - def test_mention_stream(self) -> None: - user_profile = self.example_user("othello") - msg = Message(sender=user_profile, sending_client=get_client("test")) - - content = "@**stream** test" - rendering_result = render_markdown(msg, content) - self.assertEqual( - rendering_result.rendered_content, - '

@stream test

', - ) - self.assertTrue(rendering_result.mentions_stream_wildcard) - - def test_mention_at_wildcard(self) -> None: - user_profile = self.example_user("othello") - msg = Message(sender=user_profile, sending_client=get_client("test")) - - content = "@all test" - rendering_result = render_markdown(msg, content) - self.assertEqual(rendering_result.rendered_content, "

@all test

") - self.assertFalse(rendering_result.mentions_stream_wildcard) - self.assertEqual(rendering_result.mentions_user_ids, set()) - - def test_mention_at_everyone(self) -> None: - user_profile = self.example_user("othello") - msg = Message(sender=user_profile, sending_client=get_client("test")) - - content = "@everyone test" - rendering_result = render_markdown(msg, content) - self.assertEqual(rendering_result.rendered_content, "

@everyone test

") - self.assertFalse(rendering_result.mentions_stream_wildcard) - self.assertEqual(rendering_result.mentions_user_ids, set()) + for stream_wildcard in stream_wildcards: + content = f"@{stream_wildcard} test" + rendering_result = render_markdown(msg, content) + self.assertEqual(rendering_result.rendered_content, f"

@{stream_wildcard} test

") + self.assertFalse(rendering_result.mentions_stream_wildcard) + self.assertEqual(rendering_result.mentions_user_ids, set()) def test_mention_word_starting_with_at_wildcard(self) -> None: user_profile = self.example_user("othello")