The test clients

Two special classes are provided which you can use to test your use of Akismet without needing to make real requests to the Akismet web service, and also without needing to build and maintain a set of test mocks to replace the real Akismet clients. Both of these clients are configured by subclassing them and setting attributes to specify the desired behavior.

For examples of using these test clients, see the testing section of the usage guide.

class akismet.TestAsyncClient(config: akismet.Config | None = None, http_client: AsyncClient | None = None)[source]

A version of akismet.AsyncClient for use in testing.

This client exposes exactly the same API as AsyncClient, but will not make real requests to the Akismet web service. Instead it will return fixed responses for most Akismet API operations. The two configurable responses are comment-check and verify-key, which can be controlled by subclassing this class and setting the following attributes:

comment_check_response

A value from the akismet.CheckResponse enum, indicating the desired return value of the comment-check operation. Defaults to SPAM if not specified. Use this to test code which needs to handle the various possible responses from the Akismet API.

verify_key_response

A bool indicating the desired return value of the verify-key operation. Defaults to True if not specified. Use this to test code which may need to handle or recover from invalid or missing Akismet configuration.

Note that although you can pass the http_client argument to the constructors as with the base AsyncClient, this class will ignore that argument and instead always uses its own custom HTTP client to produce the desired fixed responses.

For operations other than comment-check and verify-key, the response values will be:

class akismet.TestSyncClient(config: akismet.Config | None = None, http_client: Client | None = None)[source]

A version of akismet.SyncClient for use in testing.

This client exposes exactly the same API as SyncClient, but will not make real requests to the Akismet web service. Instead it will return fixed responses for most Akismet API operations. The two configurable responses are comment-check and verify-key, which can be controlled by subclassing this class and setting the following attributes:

comment_check_response

A value from the akismet.CheckResponse enum, indicating the desired return value of the comment-check operation. Defaults to SPAM if not specified. Use this to test code which needs to handle the various possible responses from the Akismet API.

verify_key_response

A bool indicating the desired return value of the verify-key operation. Defaults to True if not specified. Use this to test code which may need to handle or recover from invalid or missing Akismet configuration.

Note that although you can pass the http_client argument to the constructors as with the base SyncClient, this class will ignore that argument and instead always uses its own custom HTTP client to produce the desired fixed responses.

For operations other than comment-check and verify-key, the response values will be: