test_helpers: Move patch_queue_publish to test_service_bot_system.

This prepares us to tighten the type annotations for this helper.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2022-08-22 13:50:23 -04:00
committed by Tim Abbott
parent 30536caa68
commit 32a77fc0bf
2 changed files with 15 additions and 16 deletions

View File

@@ -4,7 +4,6 @@ import re
import sys
import time
from contextlib import contextmanager
from functools import wraps
from typing import (
IO,
TYPE_CHECKING,
@@ -722,17 +721,3 @@ def mock_queue_publish(
with mock.patch(method_to_patch, side_effect=verify_serialize):
yield inner
def patch_queue_publish(
method_to_patch: str,
) -> Callable[[Callable[..., None]], Callable[..., None]]:
def inner(func: Callable[..., None]) -> Callable[..., None]:
@wraps(func)
def _wrapped(*args: object, **kwargs: object) -> None:
with mock_queue_publish(method_to_patch) as m:
func(*args, m, **kwargs)
return _wrapped
return inner

View File

@@ -13,7 +13,7 @@ from zerver.lib.bot_config import ConfigError, load_bot_config_template, set_bot
from zerver.lib.bot_lib import EmbeddedBotEmptyRecipientsList, EmbeddedBotHandler, StateHandler
from zerver.lib.bot_storage import StateError
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import patch_queue_publish
from zerver.lib.test_helpers import mock_queue_publish
from zerver.lib.validator import check_string
from zerver.models import Recipient, UserProfile, get_realm
@@ -432,6 +432,20 @@ def for_all_bot_types(
return _wrapped
def patch_queue_publish(
method_to_patch: str,
) -> Callable[[Callable[..., None]], Callable[..., None]]:
def inner(func: Callable[..., None]) -> Callable[..., None]:
@wraps(func)
def _wrapped(*args: object, **kwargs: object) -> None:
with mock_queue_publish(method_to_patch) as m:
func(*args, m, **kwargs)
return _wrapped
return inner
class TestServiceBotEventTriggers(ZulipTestCase):
def setUp(self) -> None:
super().setUp()