mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 10:11:52 +00:00
* Base implementation * Added tests, fixed arguments priority * Use `Optional[X]` instead of `X | None` * Added changelog * Added tests
26 lines
799 B
Python
26 lines
799 B
Python
from unittest.mock import patch
|
|
|
|
import pytest
|
|
|
|
from aiogram.dispatcher.middlewares.user_context import UserContextMiddleware
|
|
from aiogram.types import Update
|
|
|
|
|
|
async def next_handler(*args, **kwargs):
|
|
pass
|
|
|
|
|
|
class TestUserContextMiddleware:
|
|
async def test_unexpected_event_type(self):
|
|
with pytest.raises(RuntimeError):
|
|
await UserContextMiddleware()(next_handler, object(), {})
|
|
|
|
async def test_call(self):
|
|
middleware = UserContextMiddleware()
|
|
data = {}
|
|
with patch.object(UserContextMiddleware, "resolve_event_context", return_value=[1, 2, 3]):
|
|
await middleware(next_handler, Update(update_id=42), data)
|
|
|
|
assert data["event_chat"] == 1
|
|
assert data["event_from_user"] == 2
|
|
assert data["event_thread_id"] == 3
|