forked from pgorecki/python-ddd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_command_bus.py
More file actions
41 lines (30 loc) · 1.24 KB
/
Copy pathtest_command_bus.py
File metadata and controls
41 lines (30 loc) · 1.24 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
import dependency_injector.containers as containers
import dependency_injector.providers as providers
from application.command_bus import CommandBus
from application.command_handlers import AddItemCommandHandler
from application.commands import (AddItemCommand, Command, CommandResult,
ResultStatus)
from composition_root import CommandBusContainer
class MockAuctionItemsRepository:
def add(*args, **kwargs):
pass
class OverriddenCommandBusContainer(CommandBusContainer):
items_repository = providers.Singleton(MockAuctionItemsRepository)
command_handler_factory = providers.FactoryAggregate(
AddItemCommand=providers.Factory(AddItemCommandHandler,
items_repository=items_repository
)
)
command_bus_factory = providers.Factory(
CommandBus,
command_handler_factory=providers.DelegatedFactory(
command_handler_factory)
)
def test_command_bus_will_dispatch_command():
# Arrange
bus = OverriddenCommandBusContainer.command_bus_factory()
command = AddItemCommand()
# Act
result = bus.execute(command)
# Assert
assert result.status == ResultStatus.OK