angzarr_client.testing.context¶
Scenario context for BDD-style testing.
Provides a context object for tracking state across test steps, particularly useful for Gherkin/BDD scenarios.
Classes¶
Shared context for BDD test scenarios. |
Module Contents¶
- class angzarr_client.testing.context.ScenarioContext¶
Shared context for BDD test scenarios.
Tracks the current aggregate, event history, command results, and rebuilt state across Given/When/Then steps.
- domain¶
Current aggregate domain being tested
- root¶
Current aggregate root as bytes
- events¶
List of packed events (ProtoAny) in history
- result¶
Last command handler result (event or tuple of events)
- error¶
Last CommandRejectedError if command was rejected
- state¶
Rebuilt aggregate state after applying events
Example
ctx = ScenarioContext() ctx.domain = “player” ctx.root = uuid_for(“player-alice”)
# Given player registered ctx.add_event(PlayerRegistered(email=”alice@test.com”))
# When deposit funds try:
ctx.result = handler.handle(deposit_cmd, ctx.event_book())
- except CommandRejectedError as e:
ctx.error = e
# Then balance updated assert ctx.result.new_balance == 100
- result: Any = None¶
- error: angzarr_client.errors.CommandRejectedError | None = None¶
- state: Any = None¶
- event_book() angzarr_client.proto.angzarr.EventBook¶
Build EventBook from accumulated events.
Creates an EventBook with proper sequencing from the events added via add_event().
- Returns:
EventBook with cover, pages, and next_sequence set
- add_event(event_msg)¶
Add an event to history.
Packs the event message (deriving the type URL from
event_msg.DESCRIPTOR.full_name) and appends to the event list.Audit finding #47: the previous
type_url_prefixarg is dropped — the canonical URL is derived from the message descriptor.- Parameters:
event_msg – The protobuf event message to add
- clear_events()¶
Clear all events from history.
- clear_result()¶
Clear the last result and error.
- reset()¶
Reset context to initial state.