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.
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:A value from the
akismet.CheckResponse
enum, indicating the desired return value of the comment-check operation. Defaults toSPAM
if not specified. Use this to test code which needs to handle the various possible responses from the Akismet API.
A
bool
indicating the desired return value of the verify-key operation. Defaults toTrue
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 baseAsyncClient
, 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:
submit-ham and submit-spam:
True
key-sites: the sample responses (depending on requested format) given in the Akismet web service documentation for key-sites.
usage-limit: the sample response given in the Akismet web service documentation for usage-limit.
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:A value from the
akismet.CheckResponse
enum, indicating the desired return value of the comment-check operation. Defaults toSPAM
if not specified. Use this to test code which needs to handle the various possible responses from the Akismet API.
A
bool
indicating the desired return value of the verify-key operation. Defaults toTrue
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 baseSyncClient
, 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:
submit-ham and submit-spam:
True
key-sites: the sample responses (depending on requested format) given in the Akismet web service documentation for key-sites.
usage-limit: the sample response given in the Akismet web service documentation for usage-limit.