-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_context_command_pipeline.py
More file actions
65 lines (48 loc) · 1.67 KB
/
Copy pathtest_context_command_pipeline.py
File metadata and controls
65 lines (48 loc) · 1.67 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from cq import ContextCommandPipeline, command_handler, query_handler
from tests.helpers.history import HistoryMiddleware
class TestContextCommandPipeline:
async def test_dispatch_with_success_return_any(
self,
history: HistoryMiddleware,
) -> None:
class Command1: ...
class Command2: ...
class Query: ...
class Foo: ...
class Bar: ...
class Baz: ...
@command_handler
class CommandHandler1:
async def handle(self, command: Command1) -> Foo:
return Foo()
@command_handler
class CommandHandler2:
async def handle(self, command: Command2) -> Bar:
return Bar()
@query_handler
class QueryHandler:
async def handle(self, query: Query) -> Baz:
return Baz()
class Context:
foo: Foo
bar: Bar
baz: Baz
pipeline: ContextCommandPipeline[Command1] = ContextCommandPipeline()
@pipeline.step
async def _(self, foo: Foo) -> Command2:
self.foo = foo
return Command2()
@pipeline.query_step
async def _(self, bar: Bar) -> Query:
self.bar = bar
return Query()
@pipeline.step
async def _(self, baz: Baz) -> None:
self.baz = baz
cmd = Command1()
ctx = await Context.pipeline.dispatch(cmd)
assert isinstance(ctx, Context)
assert isinstance(ctx.foo, Foo)
assert isinstance(ctx.bar, Bar)
assert isinstance(ctx.baz, Baz)
assert len(history.records) == 3