Skip to content

Query

  • Back to Testing Overview

    Return to the Testing overview page with all topics.

    Back to Overview

A query uses the same send as a command. The handler returns the view. After the read, handled, published, and outbox are empty.

See Request Handlers.

class ReadOrder(cqrs.Request[OrderView]):
    order_id: str

class ReadOrderHandler(cqrs.RequestHandler[ReadOrder]):
    async def handle(self, request: ReadOrder) -> OrderView:
        return OrderView(order_id=request.order_id)

view = await harness.mediator.send(ReadOrder(order_id="1"))
assert view.order_id == "1"
harness.handled.assert_empty()
harness.published.assert_empty()
harness.outbox.assert_empty()

Library example: examples/testing/command_and_query.py.