From 8c055107d903c7b1714c54d9797fe92ffd1332a5 Mon Sep 17 00:00:00 2001 From: Vishnu KS Date: Mon, 7 Jun 2021 21:41:26 +0530 Subject: [PATCH] exceptions: Move InvitationError to zerver/lib/exceptions. --- analytics/tests/test_counts.py | 2 +- zerver/lib/actions.py | 14 +------------- zerver/lib/exceptions.py | 14 +++++++++++++- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.py index cb498c2720..c265c38fb9 100644 --- a/analytics/tests/test_counts.py +++ b/analytics/tests/test_counts.py @@ -33,7 +33,6 @@ from analytics.models import ( installation_epoch, ) from zerver.lib.actions import ( - InvitationError, do_activate_user, do_create_realm, do_create_user, @@ -48,6 +47,7 @@ from zerver.lib.actions import ( update_user_activity_interval, ) from zerver.lib.create_user import create_user +from zerver.lib.exceptions import InvitationError from zerver.lib.test_classes import ZulipTestCase from zerver.lib.timestamp import TimezoneNotUTCException, floor_to_day from zerver.lib.topic import DB_TOPIC_NAME diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index f99158aa2c..891394bb6b 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -85,7 +85,7 @@ from zerver.lib.email_validation import ( ) from zerver.lib.emoji import check_emoji_request, emoji_name_to_emoji_code, get_emoji_file_name from zerver.lib.exceptions import ( - ErrorCode, + InvitationError, JsonableError, MarkdownRenderingException, StreamDoesNotExistError, @@ -6581,18 +6581,6 @@ def email_not_system_bot(email: str) -> None: ) -class InvitationError(JsonableError): - code = ErrorCode.INVITATION_FAILED - data_fields = ["errors", "sent_invitations"] - - def __init__( - self, msg: str, errors: List[Tuple[str, str, bool]], sent_invitations: bool - ) -> None: - self._msg: str = msg - self.errors: List[Tuple[str, str, bool]] = errors - self.sent_invitations: bool = sent_invitations - - def estimate_recent_invites(realms: Collection[Realm], *, days: int) -> int: """An upper bound on the number of invites sent in the last `days` days""" recent_invites = RealmCount.objects.filter( diff --git a/zerver/lib/exceptions.py b/zerver/lib/exceptions.py index 5a50c9f742..2aa090442d 100644 --- a/zerver/lib/exceptions.py +++ b/zerver/lib/exceptions.py @@ -1,5 +1,5 @@ from enum import Enum -from typing import Any, Dict, List, NoReturn, Optional, Type, TypeVar +from typing import Any, Dict, List, NoReturn, Optional, Tuple, Type, TypeVar from django.utils.translation import gettext as _ @@ -358,3 +358,15 @@ class InvalidSubdomainError(JsonableError): class ZephyrMessageAlreadySentException(Exception): def __init__(self, message_id: int) -> None: self.message_id = message_id + + +class InvitationError(JsonableError): + code = ErrorCode.INVITATION_FAILED + data_fields = ["errors", "sent_invitations"] + + def __init__( + self, msg: str, errors: List[Tuple[str, str, bool]], sent_invitations: bool + ) -> None: + self._msg: str = msg + self.errors: List[Tuple[str, str, bool]] = errors + self.sent_invitations: bool = sent_invitations