castlecraft_engineer.testing.query_handler
¶
castlecraft_engineer.testing.query_handler
¶
BaseQueryHandlerTest
¶
Bases: Generic[TQuery, TQueryHandler]
, ABC
Base class for testing QueryHandler implementations.
Provides common fixtures and helper methods for query handler tests.
Subclasses must define the handler_class
attribute.
Source code in src/castlecraft_engineer/testing/query_handler.py
handler_class
abstractmethod
property
¶
The specific QueryHandler class being tested.
execute_query(handler, query, subject_id=None, permissions=None, *args, **kwargs)
async
¶
Helper method to execute the query using the handler instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
handler
|
TQueryHandler
|
The query handler instance. |
required |
query
|
TQuery
|
The query instance to execute. |
required |
subject_id
|
Optional[str]
|
Optional ID of the user or system initiating the query. |
None
|
permissions
|
Optional[List[Permission]]
|
Optional list of permissions held by the subject. |
None
|
*args
|
Any
|
Additional positional arguments to pass to the handler's execute method. |
()
|
**kwargs
|
Any
|
Additional keyword arguments to pass to the handler's execute method. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
Any |
Any
|
The result of the handler's execute method. |
Source code in src/castlecraft_engineer/testing/query_handler.py
handler_instance(mock_session_factory)
¶
Provides an instance of the handler_class with mocked dependencies. Override this fixture if your handler has different dependencies.
Source code in src/castlecraft_engineer/testing/query_handler.py
mock_session()
¶
Provides a mock SQLModel Session.
Source code in src/castlecraft_engineer/testing/query_handler.py
mock_session_factory(mock_session)
¶
Provides a mock sessionmaker that returns the mock_session.