Skip to content

Commit e7efaf3

Browse files
author
José Márquez Doblas
committed
Add Bus clean method
1 parent 116650b commit e7efaf3

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

plato_cqrs/_command_bus.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ def publish(self, cmd: Command):
2121
self._semaphore.acquire()
2222
self._commands[cmd.__class__].handle(cmd)
2323
self._semaphore.release()
24+
25+
def clean(self):
26+
self._commands = {}

plato_cqrs/_query_bus.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@ def publish(self, query: Query) -> QueryResponse:
2424
response: QueryResponse = self._querys[query.__class__].handle(query)
2525
self._semaphore.release()
2626
return response
27-
27+
28+
def clean(self):
29+
self._querys = {}

plato_cqrs/tests/test_command_bus.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,11 @@ def test_cannot_subscribe_to_two_handlers(self):
3030
def test_cannot_call_a_command_without_handler(self):
3131
command_bus: CommandBus = CommandBus()
3232
with self.assertRaises(CommandHandlerDoesNotExistException):
33-
command_bus.publish(self.mockedCommnand)
33+
command_bus.publish(self.mockedCommnand)
34+
35+
def test_clean_command_bus(self):
36+
command_bus: CommandBus = CommandBus()
37+
command_bus.subscribe(self.mockedCommnand.__class__, self.mockedCommnandHandler)
38+
command_bus.clean()
39+
self.assertEqual(command_bus._commands, {})
40+

plato_cqrs/tests/test_query_bus.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,10 @@ def test_cannot_subscribe_to_two_handlers(self):
4444
def test_cannot_call_a_query_without_handler(self):
4545
query_bus: QueryBus = QueryBus()
4646
with self.assertRaises(QueryHandlerDoesNotExistException):
47-
query_bus.publish(self.mockedQuery)
47+
query_bus.publish(self.mockedQuery)
48+
49+
def test_clean_query_bus(self):
50+
query_bus: QueryBus = QueryBus()
51+
query_bus.subscribe(self.mockedQuery.__class__, self.mockedQueryHandler)
52+
query_bus.clean()
53+
self.assertEqual(query_bus._querys, {})

0 commit comments

Comments
 (0)