mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Merge branch 'dev-3.x' into scenes
# Conflicts: # tests/test_dispatcher/test_event/test_handler.py
This commit is contained in:
commit
82f1c8a418
20 changed files with 214 additions and 126 deletions
|
|
@ -38,7 +38,7 @@ def pytest_collection_modifyitems(config, items):
|
|||
raise UsageError(f"Invalid redis URI {redis_uri!r}: {e}")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
@pytest.fixture()
|
||||
def redis_server(request):
|
||||
redis_uri = request.config.getoption("--redis")
|
||||
return redis_uri
|
||||
|
|
@ -73,20 +73,9 @@ async def memory_storage():
|
|||
|
||||
@pytest.fixture()
|
||||
@pytest.mark.redis
|
||||
async def redis_isolation(redis_server):
|
||||
if not redis_server:
|
||||
pytest.skip("Redis is not available here")
|
||||
isolation = RedisEventIsolation.from_url(redis_server)
|
||||
try:
|
||||
await isolation.redis.info()
|
||||
except ConnectionError as e:
|
||||
pytest.skip(str(e))
|
||||
try:
|
||||
yield isolation
|
||||
finally:
|
||||
conn = await isolation.redis
|
||||
await conn.flushdb()
|
||||
await isolation.close()
|
||||
async def redis_isolation(redis_storage):
|
||||
isolation = redis_storage.create_isolation()
|
||||
return isolation
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
|
|
|
|||
|
|
@ -96,6 +96,8 @@ class TestAiohttpSession:
|
|||
await session.close()
|
||||
mocked_close.assert_called_once()
|
||||
|
||||
await session.close()
|
||||
|
||||
def test_build_form_data_with_data_only(self, bot: MockedBot):
|
||||
class TestMethod(TelegramMethod[bool]):
|
||||
__api_method__ = "test"
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ from aiogram.methods import (
|
|||
UnpinChatMessage,
|
||||
)
|
||||
from aiogram.types import (
|
||||
UNSET_PARSE_MODE,
|
||||
Animation,
|
||||
Audio,
|
||||
Chat,
|
||||
|
|
@ -75,7 +76,6 @@ from aiogram.types import (
|
|||
VideoNote,
|
||||
Voice,
|
||||
WebAppData,
|
||||
UNSET_PARSE_MODE,
|
||||
)
|
||||
from aiogram.types.message import ContentType, Message
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import functools
|
||||
from typing import Any, Dict, Union
|
||||
from typing import Any, Dict, Union, Callable, Set
|
||||
|
||||
import pytest
|
||||
from magic_filter import F as A
|
||||
|
|
@ -61,9 +61,9 @@ class TestCallableObject:
|
|||
pytest.param(SyncCallable(), {"self", "foo", "bar", "baz"}),
|
||||
],
|
||||
)
|
||||
def test_init_args_spec(self, callback, args):
|
||||
def test_init_args_spec(self, callback: Callable, args: Set[str]):
|
||||
obj = CallableObject(callback)
|
||||
assert set(obj.spec.args) == args
|
||||
assert set(obj.params) == args
|
||||
|
||||
def test_init_decorated(self):
|
||||
def decorator(func):
|
||||
|
|
@ -85,9 +85,9 @@ class TestCallableObject:
|
|||
obj1 = CallableObject(callback1)
|
||||
obj2 = CallableObject(callback2)
|
||||
|
||||
assert set(obj1.spec.args) == {"foo", "bar", "baz"}
|
||||
assert set(obj1.params) == {"foo", "bar", "baz"}
|
||||
assert obj1.callback == callback1
|
||||
assert set(obj2.spec.args) == {"foo", "bar", "baz"}
|
||||
assert set(obj2.params) == {"foo", "bar", "baz"}
|
||||
assert obj2.callback == callback2
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
@ -124,7 +124,9 @@ class TestCallableObject:
|
|||
),
|
||||
],
|
||||
)
|
||||
def test_prepare_kwargs(self, callback, kwargs, result):
|
||||
def test_prepare_kwargs(
|
||||
self, callback: Callable, kwargs: Dict[str, Any], result: Dict[str, Any]
|
||||
):
|
||||
obj = CallableObject(callback)
|
||||
assert obj._prepare_kwargs(kwargs) == result
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
from unittest import mock
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from aiogram.fsm.storage.base import BaseEventIsolation, StorageKey
|
||||
from aiogram.fsm.storage.redis import RedisEventIsolation
|
||||
from tests.mocked_bot import MockedBot
|
||||
|
||||
|
||||
|
|
@ -18,7 +22,6 @@ def create_storage_key(bot: MockedBot):
|
|||
],
|
||||
)
|
||||
class TestIsolations:
|
||||
@pytest.mark.filterwarnings("ignore::ResourceWarning")
|
||||
async def test_lock(
|
||||
self,
|
||||
isolation: BaseEventIsolation,
|
||||
|
|
@ -26,3 +29,35 @@ class TestIsolations:
|
|||
):
|
||||
async with isolation.lock(key=storage_key):
|
||||
assert True, "Are you kidding me?"
|
||||
|
||||
|
||||
class TestRedisEventIsolation:
|
||||
def test_init_without_key_builder(self):
|
||||
redis = AsyncMock()
|
||||
isolation = RedisEventIsolation(redis=redis)
|
||||
assert isolation.redis is redis
|
||||
|
||||
assert isolation.key_builder is not None
|
||||
|
||||
def test_init_with_key_builder(self):
|
||||
redis = AsyncMock()
|
||||
key_builder = AsyncMock()
|
||||
isolation = RedisEventIsolation(redis=redis, key_builder=key_builder)
|
||||
assert isolation.redis is redis
|
||||
assert isolation.key_builder is key_builder
|
||||
|
||||
def test_create_from_url(self):
|
||||
with patch("redis.asyncio.connection.ConnectionPool.from_url") as pool:
|
||||
isolation = RedisEventIsolation.from_url("redis://localhost:6379/0")
|
||||
assert isinstance(isolation, RedisEventIsolation)
|
||||
assert isolation.redis is not None
|
||||
assert isolation.key_builder is not None
|
||||
|
||||
assert pool.called_once_with("redis://localhost:6379/0")
|
||||
|
||||
async def test_close(self):
|
||||
isolation = RedisEventIsolation(redis=AsyncMock())
|
||||
await isolation.close()
|
||||
|
||||
# close is not called because connection should be closed from the storage
|
||||
# assert isolation.redis.close.called_once()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue