From 6566ca5258e56858c13a8079ebac56a7ebb42713 Mon Sep 17 00:00:00 2001 From: evgfilim1 Date: Tue, 15 Nov 2022 03:23:28 +0500 Subject: [PATCH] Fix tests --- tests/test_modules/test_commands.py | 12 ++++++------ userbot/modules/commands.py | 1 - 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/test_modules/test_commands.py b/tests/test_modules/test_commands.py index 9b1ac27..2a88e6f 100644 --- a/tests/test_modules/test_commands.py +++ b/tests/test_modules/test_commands.py @@ -132,7 +132,7 @@ async def handler() -> None: ) ) def test_register(handlers: list[tuple[HandlerT, list[str], bool]]) -> None: - """Tests register() adds all handlers to pyrogram Client""" + """Tests register() adds all handlers + help handlers to pyrogram Client""" # Don't repeat commands between handlers all_commands = set() for _, commands, _ in handlers: @@ -154,14 +154,14 @@ def test_register(handlers: list[tuple[HandlerT, list[str], bool]]) -> None: ) as mock: commands.register(fake_client) - # Three handlers will be added: "foo", edited "foo" and "bar". - assert mock.call_count == handler_count + # Four handlers will be added: "foo", edited "foo", "bar", "help" and edited "help". + assert mock.call_count == handler_count + 2 -def test_register_root() -> None: - """Tests register() adds a handler + help handler to pyrogram Client""" +def test_register_with_middlewares() -> None: + """Tests register() adds a handler + help handler + middlewares to pyrogram Client""" - commands = CommandsModule(root=True) + commands = CommandsModule(ensure_middlewares_registered=True) fake_client = Client("fake", in_memory=True) @commands.add("foo") diff --git a/userbot/modules/commands.py b/userbot/modules/commands.py index ddf7ba3..9b8b4cf 100644 --- a/userbot/modules/commands.py +++ b/userbot/modules/commands.py @@ -496,7 +496,6 @@ def register(self, client: Client) -> None: ) if self._ensure_middlewares_registered: # These middlewares are expected by the base module to be registered - # TODO (2022-11-06): flag to disable this behavior if icon_middleware not in self._middleware: self.add_middleware(icon_middleware) if translate_middleware not in self._middleware: