castlecraft_engineer.testing.command_handler
¶
castlecraft_engineer.testing.command_handler
¶
BaseCommandHandlerTest
¶
Bases: Generic[T, H]
Base class for testing CommandHandler implementations.
Provides pytest fixtures for common dependencies like sessionmaker, repository, and event publisher, allowing subclasses to focus on testing the handler's execution logic.
Source code in src/castlecraft_engineer/testing/command_handler.py
execute_command(handler_instance, command, subject_id=None, permissions=None, *args, **kwargs)
async
¶
Helper method to execute the command handler's execute method.
Source code in src/castlecraft_engineer/testing/command_handler.py
handler_instance(mock_sessionmaker, mock_repository, mock_publisher)
¶
Instantiates the handler_class with mocked dependencies.
Assumes a standard constructor signature like: Handler(sessionmaker, repository, publisher, ...)
Subclasses might need to override this fixture if their handler has a different constructor signature or requires additional mocks.
Source code in src/castlecraft_engineer/testing/command_handler.py
mock_publisher()
¶
Provides a MagicMock simulating an ExternalEventPublisher.
mock_repository()
¶
Provides a MagicMock simulating an AggregateRepository.
Source code in src/castlecraft_engineer/testing/command_handler.py
mock_session()
¶
mock_sessionmaker(mock_session)
¶
Provides a MagicMock simulating a sessionmaker callable.