Testing Utilities API Reference
API documentation for testing utilities and fixtures.
aio_azure_clients_toolbox.testing_utils.fixtures
async_cosmos()
This is unfortunately complex because the Async Cosmos Client uses an Async context manager which returns a client with sync methods.
Ultimately, we want to make it easy for a test function to mock out what the container client returns, but to do that, we have to mock:
- CosmosClient (with a context manager)
- Database Client
- Container Client
The last one is the one that we really want to make available to callers.
If you get confused (and it's unfortunately easy to be confused here),
you should litter print("Container Client", id(container_mock)) all over
so you can pin down which mock thing you are looking at.
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
cosmos_client_mock(monkeypatch, async_cosmos)
Mock out Azure Async Cosmos client
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
cosmos_deletable(async_cosmos)
Patch delete_item on container_mock.
Note: this is a lot simpler than returning what delete_item returns.
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
cosmos_insertable(async_cosmos)
Patch create_item on container_mock.
Note: this is a lot simpler than returning what create_item returns.
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
cosmos_patchable(async_cosmos)
Patch patch_item on container_mock.
Note: this is a lot simpler than returning what read_item returns.
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
cosmos_queryable(async_cosmos)
Make it possible to query a specific result back from the Cosmos mock.
Example
import itertools
_, set_return = cosmos_upsertable
return a thing ONE TIME (remember: this is an async iterator)
set_return("hello")
or repeatedly return the same thing
set_return(None, side_effect=itertools.repeat("hello"))
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
cosmos_readable(async_cosmos)
Patch read_item on container_mock.
Note: this is a lot simpler than returning what read_item returns.
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
cosmos_updatable(async_cosmos)
Patch replace_item on container_mock.
Note: this is a lot simpler than returning what replace_item returns.
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
cosmos_upsertable(async_cosmos)
Patch patch_item on container_mock.
Note: this is a lot simpler than returning what read_item returns.
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
mock_azureblob(monkeypatch)
async
Mock out Azure Blob Service client and its children.
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
mockegrid(monkeypatch)
Mock out Azure Eventgrid client
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
mockehub(monkeypatch)
Mock out Azure Blob Service client
Source code in aio_azure_clients_toolbox/testing_utils/fixtures.py
mockservicebus(monkeysession)
Mock out Azure Blob Service client