Skip to main content

Testing

·231 words·2 mins

Common Stubs dxaws_core.testing
#

This module contains canonical test doubles for core dxaws abstractions.

These stubs intentionally live alongside the runtime code (similar to botocore.stub.Stubber) so that:

  • AWS-facing semantics are modeled in exactly one place
  • provider and planner tests remain fast and deterministic
  • bugs in test doubles are fixed once and propagate everywhere

Nothing in this module should make real AWS calls. Nothing in this module should depend on boto3.

class StubAwsSession
#

Test double for :class:dxaws_core.aws_session.AwsSession

This stub models the contract of AwsSession at the provider boundary: callers request a service client by name, and receive an object that implements the expected AWS API surface.

The stub is intentionally strict:

  • only explicitly provided services are allowed
  • unexpected service requests raise AssertionError

This helps catch accidental AWS usage or wiring errors early in tests.

    def __init__(self, *, clients: dict[str, object]) -> None:
        self._clients = dict(clients)

    def client(self, service: str):
        try:
            return self._clients[service]
        except KeyError as e:
            raise AssertionError(
                f"Unexpected AWS service requested: {service}"
            ) from e

class StubPaginator
#

Minimal stub for botocore paginators.

AWS paginators return iterables of page dictionaries. For unit testing, a simple iterator over pre-defined pages is sufficient and preferable to importing botocore’s Stubber machinery.

This stub intentionally implements only the paginate() method and should be extended only if dxaws provider code requires it.

    def __init__(self, pages: list[dict]) -> None:
        self._pages = pages

    def paginate(self):
        return iter(self._pages)