From b9a8c4df8c95bc161cb4f73cd2c66c485e48bf41 Mon Sep 17 00:00:00 2001 From: Shubham Dhama Date: Thu, 21 Jun 2018 18:39:14 +0530 Subject: [PATCH] bugdown: Move BugdownRenderingException to exceptions.py. --- zerver/lib/actions.py | 3 +-- zerver/lib/bugdown/__init__.py | 4 +--- zerver/lib/exceptions.py | 3 +++ zerver/tests/test_bugdown.py | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index c54764c1ce..1b474d2acb 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -16,7 +16,6 @@ from analytics.lib.counts import COUNT_STATS, do_increment_logging_stat, \ RealmCount from zerver.lib.bugdown import ( - BugdownRenderingException, version as bugdown_version, url_embed_preview_enabled_for_realm ) @@ -120,7 +119,7 @@ from zerver.lib.alert_words import user_alert_words, add_user_alert_words, \ from zerver.lib.notifications import clear_scheduled_emails, \ clear_scheduled_invitation_emails, enqueue_welcome_emails from zerver.lib.narrow import check_supported_events_narrow_filter -from zerver.lib.exceptions import JsonableError, ErrorCode +from zerver.lib.exceptions import JsonableError, ErrorCode, BugdownRenderingException from zerver.lib.sessions import delete_user_sessions from zerver.lib.upload import attachment_url_re, attachment_url_to_path_id, \ claim_attachment, delete_message_image, upload_emoji_image diff --git a/zerver/lib/bugdown/__init__.py b/zerver/lib/bugdown/__init__.py index 7c4b28ab1e..841d93a16a 100644 --- a/zerver/lib/bugdown/__init__.py +++ b/zerver/lib/bugdown/__init__.py @@ -53,6 +53,7 @@ from zerver.models import ( ) import zerver.lib.mention as mention from zerver.lib.tex import render_tex +from zerver.lib.exceptions import BugdownRenderingException FullNameInfo = TypedDict('FullNameInfo', { 'id': int, @@ -78,9 +79,6 @@ STREAM_LINK_REGEX = r""" \*\* # ends by double asterisks """ -class BugdownRenderingException(Exception): - pass - def rewrite_local_links_to_relative(link: str) -> str: """ If the link points to a local destination we can just switch to that instead of opening a new tab. """ diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.py index 8dc538cc55..5c64f9d727 100644 --- a/zerver/lib/exceptions.py +++ b/zerver/lib/exceptions.py @@ -153,3 +153,6 @@ class StreamDoesNotExistError(JsonableError): class RateLimited(PermissionDenied): def __init__(self, msg: str="") -> None: super().__init__(msg) + +class BugdownRenderingException(Exception): + pass diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py index 6393c5abbf..73e87c3e90 100644 --- a/zerver/tests/test_bugdown.py +++ b/zerver/tests/test_bugdown.py @@ -13,6 +13,7 @@ from zerver.lib.alert_words import alert_words_in_realm from zerver.lib.camo import get_camo_url from zerver.lib.create_user import create_user from zerver.lib.emoji import get_emoji_url +from zerver.lib.exceptions import BugdownRenderingException from zerver.lib.mention import possible_mentions, possible_user_group_mentions from zerver.lib.message import render_markdown from zerver.lib.request import ( @@ -1247,7 +1248,7 @@ class BugdownApiTests(ZulipTestCase): class BugdownErrorTests(ZulipTestCase): def test_bugdown_error_handling(self) -> None: with self.simulated_markdown_failure(): - with self.assertRaises(bugdown.BugdownRenderingException): + with self.assertRaises(BugdownRenderingException): bugdown_convert('') def test_send_message_errors(self) -> None: @@ -1264,7 +1265,7 @@ class BugdownErrorTests(ZulipTestCase): msg = u'* a\n' * MAX_MESSAGE_LENGTH # Rendering is >100K characters with self.simulated_markdown_failure(): - with self.assertRaises(bugdown.BugdownRenderingException): + with self.assertRaises(BugdownRenderingException): bugdown_convert(msg)