State¶
State is managed for stateful routes by utilizing the StateStore
object.
This object has simple get
, list
, put
, delete
operations for different resource types.
Warning
Initially this object was only used internally but is now public. Overtime the API may change as it matures.
To access the state store for an instance of an OpenAIMock
object you can use the state
property.
The interface tries to adhere to the same design as the mock class by following closely to that of the official Python library client.
For example, if you access message routes in the client like this:
Then accessing the operations for the state store will looke like this:
Custom states¶
By default, the OpenAIMock
object is constructed with an empty state store. If you'd like to provide a custom initial state you can provide one.
Alternatively, you can use a Pytest fixture to pass around the custom state.