mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-08 17:13:56 +00:00
Update filters typing and cover ContentTypesFilter
This commit is contained in:
parent
9907eada32
commit
42faee0178
3 changed files with 33 additions and 5 deletions
|
|
@ -1,13 +1,25 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import cast
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
|
||||
from aiogram.api.types import ContentType, Message
|
||||
from aiogram.dispatcher.filters import ContentTypesFilter
|
||||
|
||||
|
||||
@dataclass
|
||||
class MinimalMessage:
|
||||
content_type: str
|
||||
|
||||
|
||||
class TestContentTypesFilter:
|
||||
def test_validator_empty(self):
|
||||
@pytest.mark.asyncio
|
||||
async def test_validator_empty(self):
|
||||
filter_ = ContentTypesFilter()
|
||||
assert filter_.content_types == ["text"]
|
||||
assert not filter_.content_types
|
||||
await filter_(cast(Message, MinimalMessage(ContentType.TEXT)))
|
||||
assert filter_.content_types == [ContentType.TEXT]
|
||||
|
||||
def test_validator_empty_list(self):
|
||||
filter_ = ContentTypesFilter(content_types=[])
|
||||
|
|
@ -22,3 +34,19 @@ class TestContentTypesFilter:
|
|||
def test_validator_with_bad_values(self, values):
|
||||
with pytest.raises(ValidationError):
|
||||
ContentTypesFilter(content_types=values)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"values,content_type,result",
|
||||
[
|
||||
[[], ContentType.TEXT, True],
|
||||
[[ContentType.TEXT], ContentType.TEXT, True],
|
||||
[[ContentType.PHOTO], ContentType.TEXT, False],
|
||||
[[ContentType.ANY], ContentType.TEXT, True],
|
||||
[[ContentType.TEXT, ContentType.PHOTO, ContentType.DOCUMENT], ContentType.TEXT, True],
|
||||
[[ContentType.ANY, ContentType.PHOTO, ContentType.DOCUMENT], ContentType.TEXT, True],
|
||||
],
|
||||
)
|
||||
@pytest.mark.asyncio
|
||||
async def test_call(self, values, content_type, result):
|
||||
filter_ = ContentTypesFilter(content_types=values)
|
||||
assert await filter_(cast(Message, MinimalMessage(content_type=content_type))) == result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue