From e43bc5b2fe4e0b67eb016d96f1b1bf9b41212ffa Mon Sep 17 00:00:00 2001 From: jrootjunior Date: Tue, 21 Jan 2020 17:32:36 +0200 Subject: [PATCH] More tests for commands filter --- aiogram/dispatcher/filters/command.py | 3 +++ tests/test_dispatcher/test_filters/test_command.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aiogram/dispatcher/filters/command.py b/aiogram/dispatcher/filters/command.py index 6eef0c3c..0fa49b30 100644 --- a/aiogram/dispatcher/filters/command.py +++ b/aiogram/dispatcher/filters/command.py @@ -41,6 +41,9 @@ class Command(BaseFilter): :param bot: :return: """ + if not text.strip(): + return False + # First step: separate command with arguments # "/command@mention arg1 arg2" -> "/command@mention", ["arg1 arg2"] full_command, *args = text.split(maxsplit=1) diff --git a/tests/test_dispatcher/test_filters/test_command.py b/tests/test_dispatcher/test_filters/test_command.py index f312c235..319ae2fa 100644 --- a/tests/test_dispatcher/test_filters/test_command.py +++ b/tests/test_dispatcher/test_filters/test_command.py @@ -29,10 +29,17 @@ class TestCommandFilter: ) command = Command(commands=["test", re.compile(r"test(\d+)")], commands_prefix="/") + assert await command.parse_command("/test@tbot", bot) assert not await command.parse_command("!test", bot) assert not await command.parse_command("/test@mention", bot) - assert await command.parse_command("/test@tbot", bot) assert not await command.parse_command("/tests", bot) + assert not await command.parse_command("/", bot) + assert not await command.parse_command("/ test", bot) + assert not await command.parse_command("", bot) + assert not await command.parse_command(" ", bot) + assert not await command.parse_command("test", bot) + assert not await command.parse_command(" test", bot) + assert not await command.parse_command("a", bot) result = await command.parse_command("/test@tbot some args", bot) assert isinstance(result, dict)