diff --git a/aiogram/dispatcher/filters/builtin.py b/aiogram/dispatcher/filters/builtin.py index c40546a6..09f21ed6 100644 --- a/aiogram/dispatcher/filters/builtin.py +++ b/aiogram/dispatcher/filters/builtin.py @@ -684,10 +684,10 @@ class IsReplyFilter(BoundFilter): class ForwardedMessageFilter(BoundFilter): - key = 'is_forward' + key = 'is_forwarded' - def __init__(self, is_forward: bool): - self.is_forward = is_forward + def __init__(self, is_forwarded: bool): + self.is_forward = is_forwarded async def check(self, message: Message): - return bool(getattr(message, "forward_date")) is self.is_forward + return bool(getattr(message, "forward_date")) is self.is_forwarded diff --git a/tests/test_dispatcher/test_filters/test_builtin.py b/tests/test_dispatcher/test_filters/test_builtin.py index a26fc139..4cfce465 100644 --- a/tests/test_dispatcher/test_filters/test_builtin.py +++ b/tests/test_dispatcher/test_filters/test_builtin.py @@ -1,12 +1,15 @@ from typing import Set +from datetime import datetime import pytest from aiogram.dispatcher.filters.builtin import ( Text, extract_chat_ids, - ChatIDArgumentType, + ChatIDArgumentType, ForwardedMessageFilter, ) +from aiogram.types import Message +from tests.types.dataset import MESSAGE class TestText: @@ -69,3 +72,25 @@ class TestText: ) def test_extract_chat_ids(chat_id: ChatIDArgumentType, expected: Set[int]): assert extract_chat_ids(chat_id) == expected + + +class TestForwardedMessageFilter: + async def test_filter_forwarded_messages(self): + filter = ForwardedMessageFilter(is_forwarded=True) + + forwarded_message = Message(forward_date=round(datetime(2020, 5, 21, 5, 1).timestamp()), **MESSAGE) + + not_forwarded_message = Message(**MESSAGE) + + assert await filter.check(forwarded_message) + assert not await filter.check(not_forwarded_message) + + async def test_filter_not_forwarded_messages(self): + filter = ForwardedMessageFilter(is_forwarded=False) + + forwarded_message = Message(forward_date=round(datetime(2020, 5, 21, 5, 1).timestamp()), **MESSAGE) + + not_forwarded_message = Message(**MESSAGE) + + assert await filter.check(not_forwarded_message) + assert not await filter.check(forwarded_message) diff --git a/tests/test_utils/test_markdown.py b/tests/test_utils/test_markdown.py deleted file mode 100644 index e69de29b..00000000