/
test_lifetimecontroller.py
50 lines (40 loc) · 1.61 KB
/
test_lifetimecontroller.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from unittest.mock import AsyncMock
from aiogram.dispatcher.middlewares import LifetimeControllerMiddleware
async def test_no_skip():
class Middleware(LifetimeControllerMiddleware):
pre_process = AsyncMock()
post_process = AsyncMock()
m = Middleware()
await m.trigger("pre_process_update_xxx", [1, 2, 3])
m.pre_process.assert_called_once_with(1, 3, 2)
m.post_process.assert_not_called()
await m.trigger("post_process_update_xxx", [1, 2, 3])
m.pre_process.reset_mock()
m.pre_process.assert_not_called()
m.post_process.assert_called_once_with(1, 3, 2)
async def test_skip_prefix():
class Middleware(LifetimeControllerMiddleware):
skip_patterns = ["update"]
pre_process = AsyncMock()
post_process = AsyncMock()
m = Middleware()
await m.trigger("pre_process_update_xxx", [1, 2, 3])
m.pre_process.assert_called_once_with(1, 3, 2)
m.post_process.assert_not_called()
await m.trigger("post_process_update_xxx", [1, 2, 3])
m.pre_process.reset_mock()
m.pre_process.assert_not_called()
m.post_process.assert_called_once_with(1, 3, 2)
async def test_skip():
class Middleware(LifetimeControllerMiddleware):
skip_patterns = ["update_xxx"]
pre_process = AsyncMock()
post_process = AsyncMock()
m = Middleware()
await m.trigger("pre_process_update_xxx", [1, 2, 3])
m.pre_process.assert_not_called()
m.post_process.assert_not_called()
await m.trigger("post_process_update_xxx", [1, 2, 3])
m.pre_process.reset_mock()
m.pre_process.assert_not_called()
m.post_process.assert_not_called()